Skip to content

Commit

Permalink
allow empty components on file path so long as not totally empty
Browse files Browse the repository at this point in the history
  • Loading branch information
itismadness committed Oct 12, 2020
1 parent ca96174 commit 917cf86
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/BencodeTorrent.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ function ($element) {
return strlen($element) === 0;
}
);
if (count($filter) > 0) {
throw new \RuntimeException('Cannot have empty path for a file');
if (count($filter) === count($file[$path_key]) && $file['length'] !== 0) {
throw new \RuntimeException('Cannot have a file with no path');
}
}
}
Expand Down
41 changes: 39 additions & 2 deletions tests/BencodeTorrentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,15 +465,52 @@ public function testGetEncodeNoData(): void
$bencode->getEncode();
}

public function testInvalidPath(): void
public function testEmptyPathPart(): void
{
$data = [
'encoding' => 'UTF8',
'info' => [
'files' => [
0 => [
'length' => 1234,
'path' => ['']
'path' => [
'',
'01 - test test',
]
]
],
'name' => 'test',
'length' => 1213134,
'pieces' => 'fake pieces string'
]
];
$bencode = new BencodeTorrent();
$bencode->setData($data);
$this->assertSame(
[
'total_size' => 1234,
'files' => [
0 => [
'path' => '/01 - test test',
'size' => 1234,
],
],
],
$bencode->getFileList()
);
}

public function testEmptyPath(): void
{
$data = [
'encoding' => 'UTF8',
'info' => [
'files' => [
0 => [
'length' => 1234,
'path' => [
'',
]
]
],
'name' => 'test',
Expand Down

0 comments on commit 917cf86

Please sign in to comment.