@@ -184,6 +184,12 @@ private static function compilePattern(Route $route, string $pattern, bool $isHo
184
184
$ regexp = self ::transformCapturingGroupsToNonCapturings ($ regexp );
185
185
}
186
186
187
+ // Fixed variable, could be transformed as text token
188
+ if (preg_quote ($ regexp , self ::REGEX_DELIMITER ) === $ regexp ) {
189
+ $ tokens [] = ['text ' , ($ isSeparator ? $ precedingChar : '' ).$ regexp ];
190
+ continue ;
191
+ }
192
+
187
193
if ($ important ) {
188
194
$ token = ['variable ' , $ isSeparator ? $ precedingChar : '' , $ regexp , $ varName , false , true ];
189
195
} else {
@@ -198,6 +204,8 @@ private static function compilePattern(Route $route, string $pattern, bool $isHo
198
204
$ tokens [] = ['text ' , substr ($ pattern , $ pos )];
199
205
}
200
206
207
+ $ tokens = self ::mergeContiguousTextTokens ($ tokens );
208
+
201
209
// find the first optional token
202
210
$ firstOptional = PHP_INT_MAX ;
203
211
if (!$ isHost ) {
@@ -237,6 +245,21 @@ private static function compilePattern(Route $route, string $pattern, bool $isHo
237
245
];
238
246
}
239
247
248
+ private static function mergeContiguousTextTokens (array $ tokens ): array
249
+ {
250
+ $ mergedTokens = [$ tokens [0 ]];
251
+ for ($ i = 1 ; $ i < \count ($ tokens ); ++$ i ) {
252
+ if ('text ' !== $ tokens [$ i ][0 ] || 'variable ' === end ($ mergedTokens )[0 ]) {
253
+ $ mergedTokens [] = $ tokens [$ i ];
254
+ continue ;
255
+ }
256
+
257
+ $ mergedTokens [count ($ mergedTokens ) - 1 ][1 ] .= $ tokens [$ i ][1 ];
258
+ }
259
+
260
+ return $ mergedTokens ;
261
+ }
262
+
240
263
/**
241
264
* Determines the longest static prefix possible for a route.
242
265
*/
0 commit comments