Skip to content

fix(syntax): handle column offset at file start - #678

Open
poplolioi11 wants to merge 1 commit into
projectfluent:mainfrom
poplolioi11:fix/syntax-column-offset-674
Open

poplolioi11 wants to merge 1 commit into
projectfluent:mainfrom
poplolioi11:fix/syntax-column-offset-674

Conversation

@poplolioi11

Copy link
Copy Markdown

When a source starts with LF, columnOffset(source, 0) returns -1 instead of 0. The backwards search passes -1 to lastIndexOf, which clamps it to index 0 and incorrectly counts the leading LF as preceding the requested position.

Return 0 before searching at the file-start position. Add nine regression/control tests for leading LF, empty/plain sources, CRLF, positions on and after a newline, consecutive newlines, and EOF. Positive offsets retain the existing behavior.

Fixes #674.

Validation on main 9a925d2:

  • Original source with the added tests: 2 failed, 7 passed. Patched full suite: 743 passed, 3 existing skipped, across 59 test files.
  • All workspace builds, lint, API documentation generation, and changed-file Prettier checks passed.
  • Compared published @fluent/syntax@0.19.0 with the built patched public API in real headless Chromium 151, Firefox 153, and WebKit 26.5: 2 incorrect results before, 0 after, for 14 cases per engine.
  • A local cross-check against the last line of the source prefix covered 781 synthetic strings / 4,297 valid offsets, including LF, CRLF and UTF-16 text. The published version had 156 mismatches, all at position 0 before leading LF; the patch had none.

The demonstrated impact is an invalid coordinate from the public helper. No downstream production failure has been established, and this change does not add validation for out-of-range or negative positions.

AI assisted source/test preparation and a separate static review; the validation results above were obtained by local execution.

This branch has not been deployed

No deployments
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.

columnOffset returns -1 at offset 0 when the source starts with LF

1 participant