fix: correct Token.Position.Offset when YAML contains comments#867
Open
Yanhu007 wants to merge 1 commit intogoccy:masterfrom
Open
fix: correct Token.Position.Offset when YAML contains comments#867Yanhu007 wants to merge 1 commit intogoccy:masterfrom
Yanhu007 wants to merge 1 commit intogoccy:masterfrom
Conversation
When scanning a comment, the "#" character was consumed with s.progress() which advances the source index but does not update s.offset. This caused all subsequent token offsets to be shifted by -1 for each preceding comment. Replace s.progress(ctx, 1) with s.progressOnly(ctx, 1) to also advance the offset counter when skipping the "#" character. Fixes goccy#856
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #867 +/- ##
=======================================
Coverage 80.65% 80.65%
=======================================
Files 22 22
Lines 6845 6845
=======================================
Hits 5521 5521
Misses 905 905
Partials 419 419 🚀 New features to boost your workflow:
|
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 #856
Problem
Token.Position.Offsetis incorrect when YAML contains comments. Each preceding comment shifts subsequent token offsets by-1:Root Cause
In
scanComment, the#character is consumed withs.progress(ctx, 1)which advances the source index (ctx.idx) but does not updates.offset. This creates a cumulative offset drift of-1per comment.Fix
Replace
s.progress(ctx, 1)withs.progressOnly(ctx, 1), which advances both the source index and the offset counter.All existing tests pass.