diff --git a/app/Extensions/helper/helpers.php b/app/Extensions/helper/helpers.php index ece174cd1..076f52373 100644 --- a/app/Extensions/helper/helpers.php +++ b/app/Extensions/helper/helpers.php @@ -304,6 +304,19 @@ if (! function_exists('escapeString')) { } } +if (! function_exists('regex_display_value')) { + /** + * Decode entity-encoded regex text at the presentation boundary. + * + * Blade should still render the returned value with escaped {{ }} output so regexes that + * contain HTML-looking text remain safe while displaying named groups and quotes readably. + */ + function regex_display_value(mixed $value): string + { + return html_entity_decode((string) ($value ?? ''), ENT_QUOTES | ENT_HTML5, 'UTF-8'); + } +} + if (! function_exists('realDuration')) { function realDuration(mixed $milliseconds): string diff --git a/resources/views/admin/regexes/category-edit.blade.php b/resources/views/admin/regexes/category-edit.blade.php index 9d3e87794..30a582f8d 100644 --- a/resources/views/admin/regexes/category-edit.blade.php +++ b/resources/views/admin/regexes/category-edit.blade.php @@ -43,7 +43,7 @@ id="group_regex" name="group_regex" class="pl-10 w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500" - value="{{ htmlspecialchars($regex->group_regex ?? '') }}" + value="{{ $regex->group_regex ?? '' }}" required>
@@ -66,7 +66,7 @@ name="regex" class="pl-10 w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 font-mono text-sm" rows="4" - required>{{ htmlspecialchars($regex->regex ?? '') }} + required>{{ regex_display_value($regex->regex ?? '') }}
Regex to use when categorizing releases.
@@ -87,7 +87,7 @@
+ rows="3">{{ $regex->description ?? '' }}
Description for this regex. You can include an example usenet subject this regex would match on. diff --git a/resources/views/admin/regexes/category-list.blade.php b/resources/views/admin/regexes/category-list.blade.php index 550e5ed18..48aa286b6 100644 --- a/resources/views/admin/regexes/category-list.blade.php +++ b/resources/views/admin/regexes/category-list.blade.php @@ -94,8 +94,8 @@
- {{ htmlspecialchars($row->regex) }}
+
+ {{ regex_display_value($row->regex) }}
@@ -66,7 +66,7 @@ name="regex" class="pl-10 w-full px-4 py-2 border border-gray-300 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 font-mono text-sm" rows="4" - required>{{ htmlspecialchars($regex->regex ?? '') }} + required>{{ regex_display_value($regex->regex ?? '') }}
Regex to use when grouping binaries into collections.
@@ -87,7 +87,7 @@
+ rows="3">{{ $regex->description ?? '' }}
Description for this regex. You can include an example usenet subject this regex would match on. diff --git a/resources/views/admin/regexes/collection-list.blade.php b/resources/views/admin/regexes/collection-list.blade.php index cb14fd9c4..c6ce2d28b 100644 --- a/resources/views/admin/regexes/collection-list.blade.php +++ b/resources/views/admin/regexes/collection-list.blade.php @@ -93,8 +93,8 @@
- {{ htmlspecialchars($row->regex) }}
+
+ {{ regex_display_value($row->regex) }}
Enter the regex pattern to test. Include delimiters and flags.
diff --git a/resources/views/admin/regexes/release-naming-edit.blade.php b/resources/views/admin/regexes/release-naming-edit.blade.php index 251e9f920..c592249fb 100644 --- a/resources/views/admin/regexes/release-naming-edit.blade.php +++ b/resources/views/admin/regexes/release-naming-edit.blade.php @@ -43,7 +43,7 @@ id="group_regex" name="group_regex" class="pl-10 w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500" - value="{{ htmlspecialchars($regex->group_regex ?? '') }}" + value="{{ $regex->group_regex ?? '' }}" required>@@ -66,7 +66,7 @@ name="regex" class="pl-10 w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 font-mono text-sm" rows="4" - required>{{ htmlspecialchars($regex->regex ?? '') }} + required>{{ regex_display_value($regex->regex ?? '') }}
Regex to use when renaming releases.
@@ -87,7 +87,7 @@
+ rows="3">{{ $regex->description ?? '' }}
Description for this regex. You can include an example release name this regex would match on. diff --git a/resources/views/admin/regexes/release-naming-list.blade.php b/resources/views/admin/regexes/release-naming-list.blade.php index d3bbc4b4c..e65ddc969 100644 --- a/resources/views/admin/regexes/release-naming-list.blade.php +++ b/resources/views/admin/regexes/release-naming-list.blade.php @@ -93,8 +93,8 @@
- {{ htmlspecialchars($row->regex) }}
+
+ {{ regex_display_value($row->regex) }}
Enter the regex pattern to test. Include delimiters and flags.
diff --git a/tests/Feature/AdminRegexesControllerTest.php b/tests/Feature/AdminRegexesControllerTest.php index e789d4b6f..2c0f7cd5d 100644 --- a/tests/Feature/AdminRegexesControllerTest.php +++ b/tests/Feature/AdminRegexesControllerTest.php @@ -166,6 +166,63 @@ class AdminRegexesControllerTest extends TestCase ->assertNotFound(); } + public function test_admin_regex_list_pages_decode_entity_encoded_regexes_without_double_escaping(): void + { + $admin = $this->createUserWithRole('Admin'); + $rawRegex = '/^(?P