Skip to content

Commit

Permalink
Fix error when parsing .gyp file with a backslash (#2)
Browse files Browse the repository at this point in the history
Regarding [Unify node.gyp code styling · Issue #41072 · nodejs/node](nodejs/node#41072), in `node.gyp`, multi-line character strings are combined by inserting `\` before a line break.
That causes 'Unknown escape character' error in `gyp-parser`.

This PR is a bug fix on the `gyp-parser` side.
  • Loading branch information
asamuzaK committed Dec 6, 2021
1 parent 8de2e5e commit 86591ad
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 1 deletion.
13 changes: 12 additions & 1 deletion index.js
Expand Up @@ -208,7 +208,18 @@ function parseString(input, at) {
value += String.fromCodePoint(parseInt(hexString, 16));
at += 2;
break;
} default:
}
case '\r':
if (input[at + 1] === '\n') {
at += 2;
} else {
at++;
}
break;
case '\n':
at++;
break;
default:
return [ new ParseError(input, at, 'Unknown escape character') ];
}
} else {
Expand Down
1 change: 1 addition & 0 deletions test/multiline_cr.in
@@ -0,0 +1 @@
{ 'foo': ['bar ' 'baz'], 'qux \quux': 'corge',}
Expand Down
1 change: 1 addition & 0 deletions test/multiline_cr.out
@@ -0,0 +1 @@
{ "foo": ["bar baz"], "qux quux": "corge"}
Expand Down
6 changes: 6 additions & 0 deletions test/multiline_crlf.in
@@ -0,0 +1,6 @@
{
'foo': ['bar '
'baz'],
'qux \
quux': 'corge',
}
4 changes: 4 additions & 0 deletions test/multiline_crlf.out
@@ -0,0 +1,4 @@
{
"foo": ["bar baz"],
"qux quux": "corge"
}
6 changes: 6 additions & 0 deletions test/multiline_lf.in
@@ -0,0 +1,6 @@
{
'foo': ['bar '
'baz'],
'qux \
quux': 'corge',
}
4 changes: 4 additions & 0 deletions test/multiline_lf.out
@@ -0,0 +1,4 @@
{
"foo": ["bar baz"],
"qux quux": "corge"
}

0 comments on commit 86591ad

Please sign in to comment.