diff options
| author | Sam Light <sam@lightscale.co.uk> | 2026-06-10 19:00:32 +0100 |
|---|---|---|
| committer | Sam Light <sam@lightscale.co.uk> | 2026-06-10 19:00:32 +0100 |
| commit | e4bb526bfda6aef396b551fb14a09ab9b2cfae53 (patch) | |
| tree | f7e2aa02b39eaa5a81984109f674394032a7939c | |
| parent | f71632bacf15cffc3c1a0f1d4673f04c9e8e3f55 (diff) | |
case insensitive path matching
| -rw-r--r-- | src/PathSegment.php | 2 | ||||
| -rw-r--r-- | tests/Unit/PathSegmentTest.php | 6 | ||||
| -rw-r--r-- | tests/Unit/RouterTest.php | 14 |
3 files changed, 21 insertions, 1 deletions
diff --git a/src/PathSegment.php b/src/PathSegment.php index 5333d17..9337fa1 100644 --- a/src/PathSegment.php +++ b/src/PathSegment.php @@ -46,7 +46,7 @@ class PathSegment PathSegmentType $type, ): string { return match ($type) { - PathSegmentType::Raw => $value ?? '', + PathSegmentType::Raw => strtolower($value ?? ''), PathSegmentType::Root => '<root>', PathSegmentType::Parameter => '<parameter>', }; diff --git a/tests/Unit/PathSegmentTest.php b/tests/Unit/PathSegmentTest.php index c537c38..29abb8c 100644 --- a/tests/Unit/PathSegmentTest.php +++ b/tests/Unit/PathSegmentTest.php @@ -41,6 +41,12 @@ it('gets key for type :dataset', function (PathSegmentType $type, ?string $res) ($t = PathSegmentType::Parameter)->name => [$t, '<parameter>'], ]); +it('gets raw keys lowercase', function() { + $seg = new PathSegment('TesTiNg'); + expect($seg->getType())->toBe(PathSegmentType::Raw); + expect($seg->getKey())->toBe('testing'); +}); + it('gets type :dataset', function (PathSegmentType $type) { $seg = new PathSegment($v = 'testing', $type); expect($seg->getType())->toBe($type); diff --git a/tests/Unit/RouterTest.php b/tests/Unit/RouterTest.php index 0e270ca..b3013bb 100644 --- a/tests/Unit/RouterTest.php +++ b/tests/Unit/RouterTest.php @@ -69,6 +69,20 @@ it('finds segment one falls back to parameter', function () { ->parameters->{'test2'}->toBe('anything'); }); +it('finds segment case insentive', function() { + $router = new Router(); + + $r = $router->root(); + + $c1 = $r->child('LevEl1'); + $c2 = $c1->child('LEVEL2'); + $c3 = $c2->child('level3'); + + expect($router->findSegment('/level1')?->segment)->toBe($c1); + expect($router->findSegment('/level1/level2')?->segment)->toBe($c2); + expect($router->findSegment('/LevEL1/level2/LEVEL3')?->segment)->toBe($c3); +}); + it('finds segments in complex routes', function () { $router = new Router(); |
