diff --git a/app/Services/Nzb/NzbImportService.php b/app/Services/Nzb/NzbImportService.php index 215a1bdaf..caf2734f4 100644 --- a/app/Services/Nzb/NzbImportService.php +++ b/app/Services/Nzb/NzbImportService.php @@ -394,7 +394,7 @@ class NzbImportService // Get the group names, group_id, check if it's blacklisted. $groupArr = []; foreach ($file->groups->group as $group) { - $group = (string) $group; + $group = $this->normalizeGroupName($group); // If group_id is -1 try to get a group_id. if ($groupID === -1) { @@ -641,6 +641,11 @@ class NzbImportService return NzbImportStatus::Inserted; } + protected function normalizeGroupName(\SimpleXMLElement|string $group): string + { + return trim((string) $group); + } + /** * Get all groups in the DB. */ diff --git a/tests/Unit/NzbImportServiceTest.php b/tests/Unit/NzbImportServiceTest.php index 17e46c1ff..19d042e62 100644 --- a/tests/Unit/NzbImportServiceTest.php +++ b/tests/Unit/NzbImportServiceTest.php @@ -237,6 +237,22 @@ final class NzbImportServiceTest extends TestCase $this->assertSame($expected, $service->deriveForTest($input)); } + public function test_group_names_are_trimmed_before_import(): void + { + $service = new class(['Browser' => true]) extends NzbImportService + { + public function groupNameForTest(\SimpleXMLElement $group): string + { + return $this->normalizeGroupName($group); + } + }; + + $group = simplexml_load_string(' alt.binaries.xylo '); + $this->assertInstanceOf(\SimpleXMLElement::class, $group); + + $this->assertSame('alt.binaries.xylo', $service->groupNameForTest($group)); + } + public function test_nzb_category_metadata_resolves_active_id_and_unique_case_insensitive_title(): void { $this->insertCategory(2040, 'HD', Category::STATUS_ACTIVE);