Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,9 @@ protected function parseRange(): ?array
$data['end'] = (int) $ranges[1];
}

if ($data['end'] !== null && $data['start'] >= $data['end']) {
// RFC 9110 range bounds are inclusive, so start === end is a valid
// single-byte range (`bytes=0-0`, or the final byte of a file).
if ($data['end'] !== null && $data['start'] > $data['end']) {
return null;
}

Expand Down
20 changes: 20 additions & 0 deletions tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,26 @@ public function testCanGetRange(): void
$this->assertSame(0, $this->request->getRangeStart());
$this->assertNull($this->request->getRangeEnd());

// RFC 9110 bounds are inclusive: start === end is a valid single-byte range.
$_SERVER['HTTP_RANGE'] = 'bytes=0-0';
$this->request = new Request();
$this->assertSame('bytes', $this->request->getRangeUnit());
$this->assertSame(0, $this->request->getRangeStart());
$this->assertSame(0, $this->request->getRangeEnd());

$_SERVER['HTTP_RANGE'] = 'bytes=499-499';
$this->request = new Request();
$this->assertSame('bytes', $this->request->getRangeUnit());
$this->assertSame(499, $this->request->getRangeStart());
$this->assertSame(499, $this->request->getRangeEnd());

// Start past end is still invalid.
$_SERVER['HTTP_RANGE'] = 'bytes=5-4';
$this->request = new Request();
$this->assertNull($this->request->getRangeUnit());
$this->assertNull($this->request->getRangeStart());
$this->assertNull($this->request->getRangeEnd());

$_SERVER['HTTP_RANGE'] = 'bytes=0--499';
$this->request = new Request();
$this->assertNull($this->request->getRangeUnit());
Expand Down