From 707d9e1356412ed3ee56925cc60eef40cb5134d4 Mon Sep 17 00:00:00 2001 From: Geert De Deckere Date: Mon, 20 Oct 2014 10:36:07 +0200 Subject: [PATCH 1/2] Compiled PHP for customized route matching The second parameter of `rtrim()` is a character mask. By checking if `rtrim($pathinfo, '/contact') === ''`, `$pathinfo` could be any URL containing those characters and not only "/contact" which was configured as the route path, for example: $pathinfo = '/octocat'; var_dump(rtrim($pathinfo, '/contact') === ''); // bool(true) --- book/routing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/routing.rst b/book/routing.rst index 434f13840f2..3ace162d2e7 100644 --- a/book/routing.rst +++ b/book/routing.rst @@ -822,7 +822,7 @@ variables that are passed into the expression: Behind the scenes, expressions are compiled down to raw PHP. Our example would generate the following PHP in the cache directory:: - if (rtrim($pathinfo, '/contact') === '' && ( + if ('/contact' === $pathinfo && ( in_array($context->getMethod(), array(0 => "GET", 1 => "HEAD")) && preg_match("/firefox/i", $request->headers->get("User-Agent")) )) { From 4a58d0b0fad3f6ba9ea68427a4ca9e8e44137070 Mon Sep 17 00:00:00 2001 From: Geert De Deckere Date: Mon, 20 Oct 2014 16:37:54 +0200 Subject: [PATCH 2/2] It seems strpos() is used instead of rtrim() --- book/routing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/routing.rst b/book/routing.rst index 3ace162d2e7..5e5f7f1d5db 100644 --- a/book/routing.rst +++ b/book/routing.rst @@ -822,7 +822,7 @@ variables that are passed into the expression: Behind the scenes, expressions are compiled down to raw PHP. Our example would generate the following PHP in the cache directory:: - if ('/contact' === $pathinfo && ( + if (0 === strpos($pathinfo, '/contact') && ( in_array($context->getMethod(), array(0 => "GET", 1 => "HEAD")) && preg_match("/firefox/i", $request->headers->get("User-Agent")) )) {