You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
Repository navigation
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
Parsing fails on valid JS: string literal with \0 #62
As for strconv.go, I don't think it requires extensive test coverage since it's copied from the Go stdlib, which already ensures that the code is correct. But we can add a few small test cases to detect regressions.
Seems to be related to the difference how \0 is treated in 2 languages:
in ES5 \0 is treated the same as a single byte escape sequence (even if it's not) equivalent to hex \x00 or octal \000 (octal is deprecated in strict mode) and is meant to represent U+0000
A proposed solution includes converting \0 to the \x00 on Golang side in the Semantic mode.
That seems reasonable. The details of how we handle unquoting are private to the implementation, so if we have to do some patch-work it shouldn't break anything fundamental.
Unfortunately there are a lot of subtle variations in (un)escaping rules for string literals, and the desire to lean on Go's implementation is understandable but doesn't always line up correctly with other languages. 🙍🏻♀️
Activity
bzz commentedon Mar 5, 2019
The issue comes from
strconv.go#unquoteSinglehere is a simple test case to reproducewhich results in
invalid syntaxand is showing up in the logs above though something like thisFrom original PR discussion #50 (comment)
bzz commentedon Mar 6, 2019
The cause is an error from
in this clause
bzz commentedon Mar 7, 2019
Seems to be related to the difference how
\0is treated in 2 languages:\0is treated the same as a single byte escape sequence (even if it's not) equivalent to hex\x00or octal\000(octal is deprecated instrictmode) and is meant to representU+0000A proposed solution includes converting
\0to the\x00on Golang side in the Semantic mode.Current implementation of Op
singleQuoteis supposed to behave likestrconv.Unquote, butstrconv.Unquote("'\\0'")->syntax errorstrconv.Unquote("'\x00'")->U+0000unquoteSingle("'\\0'")->syntax errorunquoteSingle("'\x00'")->syntax errorcreachadair commentedon Mar 7, 2019
That seems reasonable. The details of how we handle unquoting are private to the implementation, so if we have to do some patch-work it shouldn't break anything fundamental.
Unfortunately there are a lot of subtle variations in (un)escaping rules for string literals, and the desire to lean on Go's implementation is understandable but doesn't always line up correctly with other languages. 🙍🏻♀️
[-]Parsing fails on valid JS: string[/-][+]Parsing fails on valid JS: string literal with \0[/+]