Skip to content

fix(ui): count CRLF as one line break in getLineAndColumnFromOffset#3569

Open
yashs33244 wants to merge 1 commit into
resend:canaryfrom
yashs33244:fix/line-column-crlf
Open

fix(ui): count CRLF as one line break in getLineAndColumnFromOffset#3569
yashs33244 wants to merge 1 commit into
resend:canaryfrom
yashs33244:fix/line-column-crlf

Conversation

@yashs33244

@yashs33244 yashs33244 commented Jun 15, 2026

Copy link
Copy Markdown

Summary

getLineAndColumnFromOffset in @react-email/ui converts a character offset to a 1-based [line, column] (used by the email-validation diagnostics shown to users). Its regex /\n|\r|\r\n/g matched a Windows CRLF as two line breaks — in ordered alternation the \r branch always wins before \r\n — so line/column were inflated for any CRLF-authored template. Empirically, "a\r\nb" reported b at line 3 instead of line 2.

Changes

  • Reorder the split to /\r\n|\n|\r/g so CRLF counts as a single break
  • Subtract the matched break's full length for a consistent column, and scan the whole content so an offset between \r and \n isn't split
  • 3 regression tests + a patch changeset for @react-email/ui

LF behavior is byte-identical.

Testing

  • vitest run get-line-and-column-from-offset → 4 passed
  • Red-green proven: reverting the source fails the 2 CRLF tests, LF stays green
  • biome check clean on changed files; tsc --noEmit clean on the changed file

Summary by cubic

Fixes line/column reporting in @react-email/ui diagnostics for Windows line endings by correcting getLineAndColumnFromOffset. Positions are now accurate across CRLF and LF files.

  • Bug Fixes
    • Use /\r\n|\n|\r/g and compute columns from the end of the matched break for consistent results.
    • Consider only breaks that end at or before the offset to avoid splitting a CRLF when the offset is between \r and \n.
    • Add regression tests and a patch changeset.

Written for commit d476ad1. Summary will update on new commits.

Review in cubic

getLineAndColumnFromOffset used the regex /\n|\r|\r\n/g, where the \r
branch always matches before \r\n. A CRLF was therefore counted as two
line breaks, so the line and column reported for the email-validation
diagnostics were wrong for templates authored with Windows line endings.

Reorder the alternation to /\r\n|\n|\r/g so a CRLF matches as one break,
and subtract the matched break's full length when computing the column so
LF and CRLF stay consistent. Scan the whole content and keep only the
breaks that fully end at or before the offset, so an offset landing
between the \r and \n isn't mistaken for a lone carriage return.

LF-only behavior, including the existing 0-based first column on line 1,
is unchanged.
Copilot AI review requested due to automatic review settings June 15, 2026 03:40
@changeset-bot

changeset-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d476ad1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@react-email/ui Patch
react-email Patch
@react-email/editor Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

@yashs33244 is attempting to deploy a commit to the resend Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: Fixes a regex alternation order bug for CRLF line endings in a utility function (getLineAndColumnFromOffset). The code change is isolated, well-tested, and low-risk. It updates only the affected package with a patch changeset and adds regression tests.

Re-trigger cubic

@github-actions github-actions Bot added the linear-synced PR has been synced to Linear label Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

linear-synced PR has been synced to Linear

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants