diff --git a/.changelog/current/2329-allow-slash-in-recipes.md b/.changelog/current/2329-allow-slash-in-recipes.md new file mode 100644 index 000000000..59be1ab6b --- /dev/null +++ b/.changelog/current/2329-allow-slash-in-recipes.md @@ -0,0 +1,3 @@ +# Fixes + +- Allow slashes in recipe names diff --git a/lib/Helper/Filter/JSON/RecipeNameFilter.php b/lib/Helper/Filter/JSON/RecipeNameFilter.php index 2f2c762b2..92f9f1225 100644 --- a/lib/Helper/Filter/JSON/RecipeNameFilter.php +++ b/lib/Helper/Filter/JSON/RecipeNameFilter.php @@ -22,7 +22,7 @@ public function __construct(TextCleanupHelper $textCleanupHelper) { public function apply(array &$json): bool { // Clean up name to prevent issues - $cleanedName = $this->textCleanupHelper->cleanUp($json['name'], true, true); + $cleanedName = $this->textCleanupHelper->cleanUp($json['name'], true, false, false); $changed = ($json['name'] !== $cleanedName); // Restrict length of name diff --git a/lib/Helper/TextCleanupHelper.php b/lib/Helper/TextCleanupHelper.php index 09437a944..5d5153612 100644 --- a/lib/Helper/TextCleanupHelper.php +++ b/lib/Helper/TextCleanupHelper.php @@ -14,7 +14,8 @@ class TextCleanupHelper { public function cleanUp( ?string $str, bool $removeNewlines = true, - bool $removeSlashes = false + bool $removeSlashes = false, + bool $removeBackslashes = true ): string { if (!$str) { return ''; @@ -27,7 +28,9 @@ public function cleanUp( } $str = str_replace("\t", ' ', $str); - $str = str_replace("\\", '_', $str); + if($removeBackslashes) { + $str = str_replace("\\", '_', $str); + } // We want to remove forward-slashes for the name of the recipe, to tie it to the directory structure, which cannot have slashes if ($removeSlashes) { diff --git a/tests/Unit/Helper/Filter/JSON/RecipeNameFilterTest.php b/tests/Unit/Helper/Filter/JSON/RecipeNameFilterTest.php index 1d4f0856e..db579ebc3 100644 --- a/tests/Unit/Helper/Filter/JSON/RecipeNameFilterTest.php +++ b/tests/Unit/Helper/Filter/JSON/RecipeNameFilterTest.php @@ -47,7 +47,7 @@ public function testCleanFilter($oldName, $retCleaning, $newName, $isChanged) { $recipe['name'] = $oldName; $this->textCleaner->method('cleanUp')->willReturnMap([ - [$oldName, true, true, $retCleaning], + [$oldName, true, false, false, $retCleaning], ]); $this->assertEquals($isChanged, $this->dut->apply($recipe));