Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decode error for some chinese words #6

Open
orangemi opened this issue May 4, 2017 · 1 comment
Open

decode error for some chinese words #6

orangemi opened this issue May 4, 2017 · 1 comment

Comments

@orangemi
Copy link

orangemi commented May 4, 2017

Try this:

var utf7 = require('utf7')
var msg = '新建'
console.log(msg, utf7.encode(msg), utf7.decode(utf7.encode(msg)))

Output:

新建 +ZbBe+g- 新帀

If I change the msg to a single word , encode & decode is correct. When it msg contains 2 words it got wrong decode.

Any idea ?

@TSlivede
Copy link

The problem seems to be, that the char + is not in the regex that searches for possible base64 chars.

line 105 shouldn't be
return str.replace(/\+([A-Za-z0-9\/]*)-?/gi, function(_, chunk) {
but
return str.replace(/\+([A-Za-z0-9+\/]*)-?/gi, function(_, chunk) {

This also applies if you try to decode the utf-7 version of eg. "⏩" (utf7.encode('⏩') -> "+I+k-" -> also contains a + within the base64 part).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants