mathiasbynens / mathiasbynens/q-encoding

Underscore (ASCII 95) should be encoded to maintain reversibility

Open
#4 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
20
Forks
2
PR merge metrics
No merged PRs in 30d

Description

It appears that a literal underscore (ASCII 95) `_` is left as-is, meaning that a space (ASCII 32) and underscore are indistinguishable in the Q-encoded result.

Example:
```
var q = require("q-encoding")
var utf8 = require('utf8');
q.encode(utf8.encode("❤️ Hello _it's _me"));
```

Expected result:
```
"=E2=9D=A4=EF=B8=8F_Hello_=5Fit=27s_=5Fme"
```

Observed result:
```
"=E2=9D=A4=EF=B8=8F_Hello__it=27s__me"
```

Further example:
```
utf8.decode(q.decode(
q.encode(utf8.encode("❤️ Hello _it's _me"))
));
```

Result:
```
"❤️ Hello it's me"
```

RFC 2047 4.2(3) notes
> (3) 8-bit values which correspond to printable ASCII characters other
than "=", "?", and "_" (underscore), MAY be represented as those
characters.

So `_` is a special purpose character in the encoding (representing a space), so a literal `_` needs to be encoded *as if it were* non-ASCII.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the q.encode and q.decode entry points and reproduce the underscore examples from the issue. Verify that literal underscores are encoded distinctly from spaces, and that encoding followed by decoding preserves the original string and matches the expected output.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.