Skip to content

fix: pos_to_line_col always reports column 0#226

Merged
g-plane merged 1 commit into
g-plane:mainfrom
bartlomieju:fix-pos-to-line-col-column
Jun 2, 2026
Merged

fix: pos_to_line_col always reports column 0#226
g-plane merged 1 commit into
g-plane:mainfrom
bartlomieju:fix-pos-to-line-col-column

Conversation

@bartlomieju

Copy link
Copy Markdown
Contributor

In helpers::pos_to_line_col, the Break arm computes the column as:

ControlFlow::Break((line, offset)) => (line, pos - offset.max(pos)),

On the Break arm, offset is the byte offset of the previous newline, which
is always <= pos. Therefore offset.max(pos) is always pos, and the column
is always 0, regardless of the actual position on the line.

This regressed in #223, which changed the expression from pos - offset + 1 to
pos - offset.max(pos). Since the subtraction can never underflow on this arm
(offset <= pos), the max guard was unnecessary and produced an incorrect
result. As a consequence, every syntax-error message now reports column 0
(e.g. expected close tag for opening tag <h1> from line 4, column 0 instead of
... column 2).

This PR restores pos - offset + 1 and adds a unit test that pins the column to
a non-zero value for positions taking the Break arm. The test fails on the
current code ((1, 0) instead of (1, 1)) and passes with the fix.

The `Break` arm computed the column as `pos - offset.max(pos)`. On that arm
`offset` is the byte offset of the previous newline, which is always `<= pos`,
so `offset.max(pos)` is always `pos` and the column is always 0.

This regressed in g-plane#223, which changed the expression from `pos - offset + 1`
to `pos - offset.max(pos)` (the subtraction can never underflow on this arm, so
the `max` guard was unnecessary and broke the result). Restore `pos - offset + 1`
and add a regression test.
@netlify

netlify Bot commented Jun 1, 2026

Copy link
Copy Markdown

Deploy Preview for markup-fmt ready!

Name Link
🔨 Latest commit cc67281
🔍 Latest deploy log https://app.netlify.com/projects/markup-fmt/deploys/6a1dd6106f53930008c85c7f
😎 Deploy Preview https://deploy-preview-226--markup-fmt.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Xavrir added a commit to Xavrir/deno that referenced this pull request Jun 1, 2026
…gression

markup_fmt 0.27.2 introduced a regression in helpers::pos_to_line_col
that reports column 0 (g-plane/markup_fmt#226). Pin to the fix commit
via [patch.crates-io] to unblock CI; revert to a 0.27.3 version bump
once released.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Xavrir added a commit to Xavrir/deno that referenced this pull request Jun 1, 2026
…gression

markup_fmt 0.27.2 introduced a regression in helpers::pos_to_line_col
that reports column 0 (g-plane/markup_fmt#226). Pin to the fix commit
via [patch.crates-io] to unblock CI; revert to a 0.27.3 version bump
once released.
@g-plane g-plane merged commit 7968726 into g-plane:main Jun 2, 2026
5 checks passed
Xavrir added a commit to Xavrir/deno that referenced this pull request Jun 2, 2026
markup_fmt 0.27.3 includes the upstream fix for the pos_to_line_col
column-0 regression (g-plane/markup_fmt#226, now merged and released),
so the temporary [patch.crates-io] git pin is no longer needed.
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.

2 participants