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

Encoding issue when muddling #10

Open
Dids opened this issue Dec 27, 2017 · 1 comment
Open

Encoding issue when muddling #10

Dids opened this issue Dec 27, 2017 · 1 comment

Comments

@Dids
Copy link

Dids commented Dec 27, 2017

There seems to be an encoding issue with special characters. See below for the original and muddled versions.

var corruptRegex = /`\w[¡¢£¤¥¦§¨©ª]`/g
l=/`\w[\u00a1\u00a2\u00a3\u00a4\u00a5\u00a6\u00a7\u00a8\u00a9\u00aa]`/g

I'm assuming it's just not handling utf-8 encoding/decoding properly?


EDIT: I guess it's more of a problem specific to hackmud, now that I think about it. The output from hackmud is as follows:

{retval:"PARSE ERROR my.script (line 0 char 261): cannot use \\u00XX or \\u{00XX} unicode identifiers in ascii range in scripts. Please use hex escape (\\xXX)",success:false}
@Dids
Copy link
Author

Dids commented Dec 27, 2017

As a temporary workaround, I made a tiny little Node.js utility for converting unicode characters to the hex escaped format.

escape.js:

#!/usr/bin/env node

process.argv.slice(2).forEach(inputCharacter => {
  console.log('Input character:', inputCharacter)
  console.log('Output character:', unicodeEscape(inputCharacter))
})

function unicodeEscape (str) {
  let result = ''
  let index = 0
  let charCode
  let escape
  while (!isNaN(charCode = str.charCodeAt(index++))) {
    escape = charCode.toString(16)
    result += charCode < 256
      ? '\\x' + (charCode > 15 ? '' : '0') + escape
      : '\\u' + ('0000' + escape).slice(-4)
  }
  return result
}

Usage:

> ./escape.js ¡¢£¤¥¦§¨©ª
Input character: ¡¢£¤¥¦§¨©ª
Output character: \xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa

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

1 participant