Repository navigation
Locate a parse failure in a CR-only metadata file on its real line [patch] - #62
Open
matt-edmondson wants to merge 1 commit into
Open
matt-edmondson wants to merge 1 commit into
matt-edmondson wants to merge 1 commit into
Conversation
…atch] System.Text.Json counts lines by \n only, so in a file with CR-only line endings it reports every error on line zero, measured from the start of the file. LocationOf stopped its column walk at the first \r, which clamped the diagnostic to the end of the file's first line. Treat \r as ending a line only when \n follows it, in both the walk and the length check, and let LocationAt map the offset to Roslyn's line and column. Fixes #60 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5t9HHcsUTKWJqPdLK
|
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 #60
What was wrong
System.Text.Json counts lines by
\nonly. In a metadata file with CR-only line endings it reports every error onLineNumber: 0, withBytePositionInLinemeasured from the start of the file.MetadataFile.LocationOfstopped its column walk (and its length check) at the first\r, so the diagnostic was clamped to the end of the file's first line.What changed
EndsLine(index)helper: a character ends a line when it is\n, or the\rof a\r\npair. That is System.Text.Json's notion of a line.lengthcheck inLocationOfuse it.LocationAtthen maps the resulting offset to Roslyn's line/column, which does treat a lone\ras a line break.Tests
AMalformedMetadataFileIsReportedAtTheBadLinegains aCRdata row next toLFandCRLF. The expected column now comes from the literal bad line instead ofSplit('\n'), which only works for the LF/CRLF rows.CRrow fails (Assert.AreEqual(2, span.StartLinePosition.Line)). With it, all 67 tests pass, including the existing LF, CRLF and multi-byte/surrogate location tests.Generated by Claude Code