-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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: make lockfile parser tolerant to CRLF #4495
Conversation
**Summary** Lockfile parser fails when the lockfile had Windows-style line endings with an "Invalid token" error. This is default on Windows and, say when editing the file using vim, it is not obvious or trivial that the file endings are in Windows-style. This patch makes the parser tolareate potential "\r" chars before "\n" while keeping the existing parsing logic the same. **Test plan** Added two new unit tests.
src/lockfile/parse.js
Outdated
@@ -155,7 +159,7 @@ function* tokenise(input: string): Iterator<Token> { | |||
} | |||
|
|||
col += chop; | |||
lastNewline = input[0] === '\n'; | |||
lastNewline = input[0] === '\n' || input[1] === '\n'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does input[0] matter when input[1] === '\n'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I can change this to input[0] === '\n' || (input[0] === '\r' && input[1] === '\n')
to be precise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, one nit
This change will increase the build size from 9.69 MB to 9.7 MB, an increase of 2.09 KB (0%)
|
**Summary** Lockfile parser fails when the lockfile had Windows-style line endings with an "Invalid token" error. This is default on Windows and, say when editing the file using vim, it is not obvious or trivial that the file endings are in Windows-style. This patch makes the parser tolareate potential "\r" chars before "\n" while keeping the existing parsing logic the same. **Test plan** Added three new unit tests.
Summary
Lockfile parser fails when the lockfile had Windows-style line
endings with an "Invalid token" error. This is default on Windows
and, say when editing the file using vim, it is not obvious or
trivial that the file endings are in Windows-style. This patch
makes the parser tolareate potential "\r" chars before "\n" while
keeping the existing parsing logic the same.
Test plan
Added three new unit tests.