Skip to content

Commit 0c61d52

Browse files
authored
fix: fetch blob with range off-by-one error (#4643)
1 parent b958ea0 commit 0c61d52

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/web/fetch/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ function schemeFetch (fetchParams) {
889889

890890
// 8. Let slicedBlob be the result of invoking slice blob given blob, rangeStart,
891891
// rangeEnd + 1, and type.
892-
const slicedBlob = blob.slice(rangeStart, rangeEnd, type)
892+
const slicedBlob = blob.slice(rangeStart, rangeEnd + 1, type)
893893

894894
// 9. Let slicedBodyWithType be the result of safely extracting slicedBlob.
895895
// Note: same reason as mentioned above as to why we use extractBody

test/fetch/blob-uri.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ test('fetching blob: uris', async (t) => {
2323
t.assert.strictEqual(`${blob.size}`, res.headers.get('Content-Length'))
2424
})
2525

26+
await t.test('a range fetch request returns the inclusive byte range', async () => {
27+
const res = await fetch(objectURL, {
28+
headers: {
29+
Range: 'bytes=1-3'
30+
}
31+
})
32+
33+
t.assert.strictEqual(res.status, 206)
34+
t.assert.strictEqual(await res.text(), blobContents.slice(1, 4))
35+
t.assert.strictEqual(res.headers.get('Content-Length'), '3')
36+
t.assert.strictEqual(res.headers.get('Content-Range'), `bytes 1-3/${blob.size}`)
37+
})
38+
2639
await t.test('non-GET method to blob: fails', async () => {
2740
try {
2841
await fetch(objectURL, {

0 commit comments

Comments
 (0)