Skip to content

Commit

Permalink
Correct handling of backslashes on python unescaping
Browse files Browse the repository at this point in the history
  • Loading branch information
tedivm committed Nov 19, 2017
1 parent 5a95b7e commit 368192e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'string.fromcodepoint';
* \U([0-9A-Fa-f]+) - sixth alternative; matches the 8-digit hexadecimal escape sequence used by python (\U0001F3B5)
* )
*/
const jsEscapeRegex = /\\(u\{([0-9A-Fa-f]+)\}|u([0-9A-Fa-f]{4})|x([0-9A-Fa-f]{2})|([1-7][0-7]{0,2}|[0-7]{2,3})|(['"tbrnfv0\\]))|\U([0-9A-Fa-f]{8})/g;
const jsEscapeRegex = /\\(u\{([0-9A-Fa-f]+)\}|u([0-9A-Fa-f]{4})|x([0-9A-Fa-f]{2})|([1-7][0-7]{0,2}|[0-7]{2,3})|(['"tbrnfv0\\]))|\\U([0-9A-Fa-f]{8})/g;

const usualEscapeSequences = {
'0': '\0',
Expand Down
4 changes: 2 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ test('avoids double unescape cascade', t => {
});

test('python hex escape sequences', t => {
t.is(unescapeJs('---\U000000A9---'), '---\u00A9---');
t.is(unescapeJs('---\U0001F3B5---'), '---\uD83C\uDFB5---');
t.is(unescapeJs('---\\U000000A9---'), '---\u00A9---');
t.is(unescapeJs('---\\U0001F3B5---'), '---\uD83C\uDFB5---');
});

0 comments on commit 368192e

Please sign in to comment.