Browse Source

Merge branch 'hotfix/fix_reserved_subdomains_regex'

Olivier Massot 5 tháng trước cách đây
mục cha
commit
ae11995d6e

+ 2 - 2
src/Service/Typo3/SubdomainService.php

@@ -77,11 +77,11 @@ class SubdomainService
     {
         $reservedSubdomains = $this->parameterBag->get('opentalent.subdomains')['reserved'];
         $subRegexes = array_map(
-            function (string $s) { return '(\b'.trim($s, '^$/\s').'\b)'; },
+            function (string $s) { return '(\b'.trim($s).'\b)'; },
             $reservedSubdomains
         );
 
-        $regex = '/^'.strtolower(implode('|', $subRegexes)).'$/';
+        $regex = '/^(?:'.strtolower(implode('|', $subRegexes)).')$/';
 
         return preg_match($regex, $subdomainValue) !== 0;
     }

+ 8 - 0
tests/Unit/Service/Typo3/SubdomainServiceTest.php

@@ -159,12 +159,20 @@ class SubdomainServiceTest extends TestCase
                 ],
             ]);
 
+        // Exact match for 'abcd' should be reserved
         $this->assertTrue($subdomainService->isReservedSubdomain('abcd'));
+
+        // Pattern match for 'abc\d+' should be reserved
         $this->assertTrue($subdomainService->isReservedSubdomain('abc123'));
 
+        // These should not match any reserved pattern
         $this->assertFalse($subdomainService->isReservedSubdomain('abcde'));
         $this->assertFalse($subdomainService->isReservedSubdomain('abc'));
         $this->assertFalse($subdomainService->isReservedSubdomain('foo'));
+
+        // Test word boundary behavior
+        $this->assertFalse($subdomainService->isReservedSubdomain('myabcd')); // Should not match due to word boundary
+        $this->assertFalse($subdomainService->isReservedSubdomain('abcdfoo')); // Should not match due to word boundary
     }
 
     public function testIsRegisteredSubdomain(): void