fix(ui): count CRLF as one line break in getLineAndColumnFromOffset#3569
Conversation
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.
🦋 Changeset detectedLatest commit: d476ad1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
|
@yashs33244 is attempting to deploy a commit to the resend Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
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
commit: |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
dielduarte
left a comment
There was a problem hiding this comment.
thanks for the contribution!
Summary
getLineAndColumnFromOffsetin@react-email/uiconverts a character offset to a 1-based[line, column](used by the email-validation diagnostics shown to users). Its regex/\n|\r|\r\n/gmatched a Windows CRLF as two line breaks — in ordered alternation the\rbranch always wins before\r\n— so line/column were inflated for any CRLF-authored template. Empirically,"a\r\nb"reportedbat line 3 instead of line 2.Changes
/\r\n|\n|\r/gso CRLF counts as a single break\rand\nisn't splitpatchchangeset for@react-email/uiLF behavior is byte-identical.
Testing
vitest run get-line-and-column-from-offset→ 4 passedbiome checkclean on changed files;tsc --noEmitclean on the changed fileSummary by cubic
Fixes line/column reporting in
@react-email/uidiagnostics for Windows line endings by correctinggetLineAndColumnFromOffset. Positions are now accurate across CRLF and LF files./\r\n|\n|\r/gand compute columns from the end of the matched break for consistent results.\rand\n.Written for commit d476ad1. Summary will update on new commits.