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: v8 coverage ranges that fall on \n characters cause exceptions #96

Merged
merged 1 commit into from Mar 27, 2020

Conversation

j03m
Copy link
Contributor

@j03m j03m commented Mar 27, 2020

When a file has dos line endings \r\n we found a few instances in a large codebase
where v8 would report the position of the \n as startCol for a range. This would
cause the starting column supplied to sourceMap.originalPositionFor to be a -1
because the startColumns of the transpiled source lines were calculated as
endCol + length of line break sequence. This value is invalid causing sourceMap.originalPositionFor to throw with Column numbers must be >= 0.

To replicate this condition, revert the fix but run the new unit test. The
call to applyCoverage will crash. While the unit test range was hand
crafted by me for this particular example, we saw this coming up in the
wild.

This change clamps the supplied value to a min of 0 and adds a test
fixture (force encoded as \r\n) to test for it. The encoding are maintained
across varying gitconfigs via entries in .gitattributes

When a file has dos line endings \r\n we found a few instances in a large codebase
where v8 would report the position of the \n as startCol for a range. This would
cause the starting column supplied to sourceMap.originalPositionFor to be a -1
because the startColumns of the transpiled source lines were calculated as
endCol + length of line break sequence.

To replicate this condition, revert the fix but run the new unit test. The
call to `applyCoverage` will crash. While the unit test range was hand
crafted by me for this particular example, we saw this coming up in the
wild.

This change clamps the supplied value to
max 0 and adds a test fixture (force encoded as \r\n) to test for it.
@coveralls
Copy link

Pull Request Test Coverage Report for Build 420

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 95.298%

Totals Coverage Status
Change from base Build 418: 0.0%
Covered Lines: 513
Relevant Lines: 532

💛 - Coveralls

@bcoe bcoe merged commit c5731a3 into istanbuljs:master Mar 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants