Skip to content

Commit 917cf86

Browse files
author
itismadness
committed
allow empty components on file path so long as not totally empty
1 parent ca96174 commit 917cf86

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

src/BencodeTorrent.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ function ($element) {
105105
return strlen($element) === 0;
106106
}
107107
);
108-
if (count($filter) > 0) {
109-
throw new \RuntimeException('Cannot have empty path for a file');
108+
if (count($filter) === count($file[$path_key]) && $file['length'] !== 0) {
109+
throw new \RuntimeException('Cannot have a file with no path');
110110
}
111111
}
112112
}

tests/BencodeTorrentTest.php

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,15 +465,52 @@ public function testGetEncodeNoData(): void
465465
$bencode->getEncode();
466466
}
467467

468-
public function testInvalidPath(): void
468+
public function testEmptyPathPart(): void
469469
{
470470
$data = [
471471
'encoding' => 'UTF8',
472472
'info' => [
473473
'files' => [
474474
0 => [
475475
'length' => 1234,
476-
'path' => ['']
476+
'path' => [
477+
'',
478+
'01 - test test',
479+
]
480+
]
481+
],
482+
'name' => 'test',
483+
'length' => 1213134,
484+
'pieces' => 'fake pieces string'
485+
]
486+
];
487+
$bencode = new BencodeTorrent();
488+
$bencode->setData($data);
489+
$this->assertSame(
490+
[
491+
'total_size' => 1234,
492+
'files' => [
493+
0 => [
494+
'path' => '/01 - test test',
495+
'size' => 1234,
496+
],
497+
],
498+
],
499+
$bencode->getFileList()
500+
);
501+
}
502+
503+
public function testEmptyPath(): void
504+
{
505+
$data = [
506+
'encoding' => 'UTF8',
507+
'info' => [
508+
'files' => [
509+
0 => [
510+
'length' => 1234,
511+
'path' => [
512+
'',
513+
]
477514
]
478515
],
479516
'name' => 'test',

0 commit comments

Comments
 (0)