Fix JS extractor line numbers being off on CRLF files#1288
Open
apoorva-01 wants to merge 1 commit into
Open
Conversation
The `//` and `<!--` line-comment rules matched with `.*`, which also consumes the `\r` of a CRLF newline (only `\n` stops `.`). The comment token therefore carried a trailing `\r` that `line_re` counted as a line break, and the following lone `\n` was counted again by the whitespace rule, so every comment line advanced the counter twice. Messages extracted after a comment ended up shifted down by one line per preceding comment line on CRLF-formatted files. Restrict both rules to `[^\r\n]` so the comment stops before the newline and the CRLF pair is counted once by the whitespace rule.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #770
The JS extractor reports different line numbers depending on line endings — a call after three comment lines shows up on line 4 with LF but line 7 with CRLF, which is the Linux/Windows difference the reporter hit.
It's the
//and<!--comment rules in jslexer: they match with.*, and.eats the\rof a CRLF, so the comment token keeps a trailing\rthat gets counted as a newline, and then the\nis counted again — two lines per comment. Switching both to[^\r\n]*stops the comment before the newline so the\r\nis counted once. Added tests that the LF and CRLF line numbers match.Left CHANGES.rst alone since it looks like that's filled in at release time, but happy to add an entry if you'd prefer.