| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 59af7e0 commit 21e2420
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -122,7 +122,7 @@ function getSource(source, endings) { | |||
| 122 | 122 | source = new Uint8Array(source); | |
| 123 | 123 | } else if (!isArrayBufferView(source)) { | |
| 124 | 124 | if (endings === 'native') | |
| 125 | - source = RegExpPrototypeSymbolReplace(/\n|\r\n/g, source, EOL); | ||
| 125 | + source = RegExpPrototypeSymbolReplace(/\r\n|\r|\n/g, source, EOL); | ||
| 126 | 126 | source = enc.encode(source); | |
| 127 | 127 | } | |
| 128 | 128 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -407,6 +407,24 @@ assert.throws(() => new Blob({}), { | |||
| 407 | 407 | const b = new Blob(['hello\n'], { endings: 'native' }); | |
| 408 | 408 | assert.strictEqual(b.size, EOL.length + 5); | |
| 409 | 409 | ||
| 410 | + // The WHATWG "convert line endings to native" algorithm normalizes every | ||
| 411 | + // standalone "\r", "\n", and "\r\n" sequence to the native line ending. | ||
| 412 | + // Refs: https://w3c.github.io/FileAPI/#convert-line-endings-to-native | ||
| 413 | + (async () => { | ||
| 414 | + const cases = [ | ||
| 415 | + ['a\rb', `a${EOL}b`], | ||
| 416 | + ['a\nb', `a${EOL}b`], | ||
| 417 | + ['a\r\nb', `a${EOL}b`], | ||
| 418 | + ['a\r\rb', `a${EOL}${EOL}b`], | ||
| 419 | + ['a\n\rb', `a${EOL}${EOL}b`], | ||
| 420 | + ['\r\n\r', `${EOL}${EOL}`], | ||
| 421 | + ]; | ||
| 422 | + for (const [input, expected] of cases) { | ||
| 423 | + const blob = new Blob([input], { endings: 'native' }); | ||
| 424 | + assert.strictEqual(await blob.text(), expected); | ||
| 425 | + } | ||
| 426 | + })().then(common.mustCall()); | ||
| 427 | + | ||
| 410 | 428 | [1, {}, 'foo'].forEach((endings) => { | |
| 411 | 429 | assert.throws(() => new Blob([], { endings }), { | |
| 412 | 430 | code: 'ERR_INVALID_ARG_VALUE', | |
| Back | FazBrowse Home | New Git URL |
0 commit comments