@@ -98,17 +98,24 @@ public function __construct(string $pattern, $callback, array $methods, bool $pa
9898 * Checks if a URL matches the route pattern. Also parses named parameters in the URL.
9999 *
100100 * @param string $url Requested URL (original format, not URL decoded)
101- * @param bool $case_sensitive Case sensitive matching
101+ * @param bool $caseSensitive Case sensitive matching
102102 *
103103 * @return bool Match status
104104 */
105- public function matchUrl (string $ url , bool $ case_sensitive = false ): bool
105+ public function matchUrl (string $ url , bool $ caseSensitive = false ): bool
106106 {
107107 // Wildcard or exact match
108108 if ($ this ->pattern === '* ' || $ this ->pattern === $ url ) {
109109 return true ;
110110 }
111111
112+ // if the last character of the incoming url is a slash, only allow one trailing slash, not multiple
113+ if (substr ($ url , -2 ) === '// ' ) {
114+ // remove all trailing slashes, and then add one back.
115+ $ url = rtrim ($ url , '/ ' ) . '/ ' ;
116+ }
117+
118+
112119 $ ids = [];
113120 $ last_char = substr ($ this ->pattern , -1 );
114121
@@ -157,7 +164,7 @@ static function ($matches) use (&$ids) {
157164 $ regex .= $ last_char === '/ ' ? '? ' : '/? ' ;
158165
159166 // Attempt to match route and named parameters
160- if (!preg_match ('#^ ' . $ regex . '(?:\?[\s\S]*)?$# ' . (($ case_sensitive ) ? '' : 'i ' ), $ url , $ matches )) {
167+ if (!preg_match ('#^ ' . $ regex . '(?:\?[\s\S]*)?$# ' . (($ caseSensitive ) ? '' : 'i ' ), $ url , $ matches )) {
161168 return false ;
162169 }
163170
0 commit comments