Allow optional spaces in Range header parsing

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-10 04:29:07 +00:00
1 parent 0431e648c8
commit aa455d13cc
2 files changed
+8 -1

No files matched your search

+7
View File
@@ -928,6 +928,13 @@ describe("parseByteRangeHeader", () => {
});
});
it("tolerates optional whitespace around separators", () => {
expect(parseByteRangeHeader("bytes = 0 - 9", 100)).toEqual({
start: 0,
end: 9,
});
});
it("parses case-insensitive byte-unit prefixes", () => {
expect(parseByteRangeHeader("ByTeS=0-9", 100)).toEqual({
start: 0,
+1 -1
View File
@@ -661,7 +661,7 @@ export function parseByteRangeHeader(
return "invalid";
}
const match = rangeHeaderValue.trim().match(/^bytes=(\d*)-(\d*)$/i);
const match = rangeHeaderValue.trim().match(/^bytes\s*=\s*(\d*)\s*-\s*(\d*)$/i);
if (!match) {
return "invalid";
}