Skip to content

Commit 67d7605

Browse files
authored
Improve routes matching (#185)
1 parent 3033fc7 commit 67d7605

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@
6464
"minimum-stability": "dev",
6565
"prefer-stable": true,
6666
"config": {
67-
"sort-packages": true
67+
"sort-packages": true,
68+
"allow-plugins": {
69+
"dealerdirect/phpcodesniffer-composer-installer": true
70+
}
6871
},
6972
"extra": {
7073
"branch-alias": {

src/Core/Schema/Endpoint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,15 +313,15 @@ private function generatePattern(): string
313313

314314
if ($suffixes) {
315315
return sprintf(
316-
'#%s' . // Always start with raw pattern
316+
'#^%s' . // Always start with raw pattern
317317
'(%s)?$#U', // Optionally followed by one of suffixes
318318
$rawPattern,
319319
implode('|', array_map('preg_quote', $suffixes))
320320
);
321321
}
322322

323323
return sprintf(
324-
'#%s$#', // Exactly match raw pattern
324+
'#^%s$#', // Exactly match raw pattern
325325
$rawPattern
326326
);
327327
}

tests/Cases/Core/DI/ApiExtension.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ test(function (): void {
6767
Assert::count(4, $schema->getEndpoints());
6868
Assert::equal(['GET'], $schema->getEndpoints()[0]->getMethods());
6969
Assert::equal('/api/v1/foobar/baz1', $schema->getEndpoints()[0]->getMask());
70-
Assert::equal('#/api/v1/foobar/baz1$#', $schema->getEndpoints()[0]->getPattern());
70+
Assert::equal('#^/api/v1/foobar/baz1$#', $schema->getEndpoints()[0]->getPattern());
7171
Assert::equal([], $schema->getEndpoints()[0]->getParameters());
7272
Assert::equal(AnnotationFoobarController::class, $schema->getEndpoints()[0]->getHandler()->getClass());
7373
Assert::equal('baz1', $schema->getEndpoints()[0]->getHandler()->getMethod());

tests/Cases/Core/Schema/Serialization/ArrayHydrator.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ test(function (): void {
9191
Assert::same('/group1-path/group2-path/c1-path/m2-path', $endpoint1->getMask());
9292
Assert::same('/group1-path/group2-path/c1-path/m2-path', $endpoint1->getAttribute('pattern'));
9393
Assert::same(null, $endpoint1->getAttribute('missing'));
94-
Assert::same('#/group1-path/group2-path/c1-path/m2-path$#', $endpoint1->getPattern());
94+
Assert::same('#^/group1-path/group2-path/c1-path/m2-path$#', $endpoint1->getPattern());
9595
Assert::same([], $endpoint1->getParameters());
9696
Assert::same([], $endpoint1->getNegotiations());
9797

@@ -114,7 +114,7 @@ test(function (): void {
114114
Assert::same('/group1-path/group2-path/c1-path/m3-path/{m3-p1}', $endpoint2->getMask());
115115
Assert::same('/group1-path/group2-path/c1-path/m3-path/(?P<m3-p1>[^/]+)', $endpoint2->getAttribute('pattern'));
116116
Assert::same(null, $endpoint2->getAttribute('missing'));
117-
Assert::same('#/group1-path/group2-path/c1-path/m3-path/(?P<m3-p1>[^/]+)(json|xml)?$#U', $endpoint2->getPattern());
117+
Assert::same('#^/group1-path/group2-path/c1-path/m3-path/(?P<m3-p1>[^/]+)(json|xml)?$#U', $endpoint2->getPattern());
118118

119119
Assert::same(null, $endpoint2->getRequestBody());
120120

0 commit comments

Comments
 (0)