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

Fix error when parsing .gyp file with a backslash #2

Merged
merged 3 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ function parseString(input, at) {
if (input[at] !== '"' && input[at] !== "'")
return [ new ParseError(input, at, 'Expected \' or "') ];
const type = input[at++];
const cr = String.fromCodePoint(0x0D);
const lf = String.fromCodePoint(0x0A);
let value = '';
while (input[at] !== type) {
if (input[at] === '\\') {
Expand Down Expand Up @@ -208,7 +210,18 @@ function parseString(input, at) {
value += String.fromCodePoint(parseInt(hexString, 16));
at += 2;
break;
} default:
}
case cr:
if (input[at + 1] === lf) {
at += 2;
} else {
at++;
}
break;
case lf:
at++;
break;
default:
return [ new ParseError(input, at, 'Unknown escape character') ];
}
} else {
Expand Down
1 change: 1 addition & 0 deletions test/multiline_cr.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ 'foo': ['bar ' 'baz'], 'qux \quux': 'corge',}
Expand Down
1 change: 1 addition & 0 deletions test/multiline_cr.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "foo": ["bar baz"], "qux quux": "corge"}
Expand Down
6 changes: 6 additions & 0 deletions test/multiline_crlf.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
'foo': ['bar '
'baz'],
'qux \
quux': 'corge',
}
4 changes: 4 additions & 0 deletions test/multiline_crlf.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"foo": ["bar baz"],
"qux quux": "corge"
}
6 changes: 6 additions & 0 deletions test/multiline_lf.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
'foo': ['bar '
'baz'],
'qux \
quux': 'corge',
}
4 changes: 4 additions & 0 deletions test/multiline_lf.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"foo": ["bar baz"],
"qux quux": "corge"
}