Skip to content

Commit 9362fa8

Browse files
committed
[Router] allow to use \A and \z as regex start and end
1 parent 80e38d2 commit 9362fa8

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Symfony/Component/Routing/Route.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,9 @@ public function compile()
546546

547547
private function sanitizeRequirement(string $key, string $regex)
548548
{
549+
// Replace \A, \z with classic ^ and $
550+
$regex = str_replace(['\A', '\z'], ['^', '$'], $regex);
551+
549552
if ('' !== $regex && '^' === $regex[0]) {
550553
$regex = (string) substr($regex, 1); // returns false for a single character
551554
}

src/Symfony/Component/Routing/Tests/RouteTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ public function testRequirement()
122122
$this->assertTrue($route->hasRequirement('foo'), '->hasRequirement() return true if requirement is set');
123123
}
124124

125+
public function testRequirementAlternativeStartAndEndRegexSyntax()
126+
{
127+
$route = new Route('/{foo}');
128+
$route->setRequirement('foo', '\A\d+\z');
129+
$this->assertEquals('\d+', $route->getRequirement('foo'), '->setRequirement() removes \A and \z from the path');
130+
$this->assertTrue($route->hasRequirement('foo'));
131+
}
132+
125133
/**
126134
* @dataProvider getInvalidRequirements
127135
*/
@@ -139,6 +147,9 @@ public function getInvalidRequirements()
139147
['^$'],
140148
['^'],
141149
['$'],
150+
['\A\z'],
151+
['\A'],
152+
['\z'],
142153
];
143154
}
144155

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy