Skip to content

buffer: normalize lone "\r" in Blob native line endings#64115

Open
watilde wants to merge 1 commit into
nodejs:mainfrom
watilde:fix-blob-native-endings-lone-cr
Open

buffer: normalize lone "\r" in Blob native line endings#64115
watilde wants to merge 1 commit into
nodejs:mainfrom
watilde:fix-blob-native-endings-lone-cr

Conversation

@watilde

@watilde watilde commented Jun 24, 2026

Copy link
Copy Markdown
Member

new Blob(parts, { endings: 'native' }) failed to normalize a standalone carriage return. The replacement regex only matched \n and \r\n, so a lone \r (and runs such as \r\r) were left untouched instead of being converted to the platform's native line ending.

The WHATWG "convert line endings to native" algorithm requires \r, \n, and \r\n to all be normalized. Match \r\n before a lone \r so that CRLF collapses to a single native ending.

Refs: https://w3c.github.io/FileAPI/#convert-line-endings-to-native

`new Blob(parts, { endings: 'native' })` failed to normalize a
standalone carriage return. The replacement regex only matched
`\n` and `\r\n`, so a lone `\r` (and runs such as `\r\r`) were
left untouched instead of being converted to the platform's
native line ending.

The WHATWG "convert line endings to native" algorithm requires
`\r`, `\n`, and `\r\n` to all be normalized. Match `\r\n` before
a lone `\r` so that CRLF collapses to a single native ending.

Refs: https://w3c.github.io/FileAPI/#convert-line-endings-to-native

Signed-off-by: Daijiro Wachi <daijiro.wachi@gmail.com>
@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants