New issue
Advanced search Search tips
Starred by 2 users

Issue metadata

Status: WorkingAsIntended
Merged: issue 4829
Owner: ----
Closed: May 2016
HW: ----
NextAction: ----
OS: ----
Priority: 2
Type: Bug

Sign in to add a comment

Inconsistency in the String.raw()

Reported by, May 15 2016 Back to list

Issue description

Version: (from Node.js 6.1.0), 5.2.323 (from Chrome Canary 52.0.2737.0)
OS: Windows 7
Architecture: x64

What steps will reproduce the problem?

Enter in the Chrome console or execute by the Node.js script:


What is the expected output?


What do you see instead?

Uncaught SyntaxError: Invalid hexadecimal escape sequence (Chrome)
SyntaxError: missing ) after argument list (Node.js)
Also compare:


Uncaught SyntaxError: Invalid Unicode escape sequence (Chrome)
SyntaxError: missing ) after argument list (Node.js)

Other escape notation work as expected (\0, \n, \r, \v, \t, \b, \f).
Mergedinto: 4829
Status: Duplicate (was: Untriaged)
See v8:4829 --- The updated error message in Chrome due to fixing this bug.

Versions of Node.js which include e6f4b7491c434773f0a59a36ce98db40ea31bce2 will of course not be inconsistent with Chrome here.
Will v8:4829 fixed allow String.raw`с:\x.js`? Will it be === 'с:\\x.js'?
No, `C:\x.js` is an invalid string / template string, due to the bad EscapeSequence (
By "Inconsistency" I meant not the Chrome vs Node.js difference or error messages difference. I mean: in the first case the escape sequence is not interpreted as escape sequence, while in the second case the escape sequence is tried to be interpreted as escape sequence.
Well, \x5c is a legitimate HexEscapeSequence (`\x` followed by 2 HexDigits), whereas `\x.js` is not ('.' is not a HexDigit). Both of them are parsed as EscapeSequences, but one of them fails to be parsed this way.
Status: WorkingAsIntended (was: Duplicate)
Oh. Thank you. Sorry, I misunderstood the first case then. In the MDN:

The static String.raw() method is a tag function of template literals, similar to the r prefix in Python or the @ prefix in C# for string literals. It's used to get the raw string form of template strings (that is, the original, uninterpreted text).

I thought it also similar to Perl single quotes.
That looks like a place where MDN could use some improvement =) String.raw will use the  TRV ( of the string (including the EscapeSequence production) --- which means that it will serialize `\x5c` as "\\x5c". But, when parsing the script, it is still parsed as an escape sequence --- and failing to parse this escape sequence is a SyntaxError.

I hope that clears everything up, I suggest submitting a fix for clarifying the docs on MDN
Unfortunately, I have no experience in contributing to the MDN. However, I've added a note and a link. I hope some more experienced MDN author will turn them into the more appropriate fixes.
Labels: Priority-2

Sign in to add a comment