@@ -142,32 +142,30 @@ public boolean matches(String uri) {
142142 }
143143
144144 // Convert the URI template into a robust regex pattern that escapes special
145- // characters like '?'.
146- StringBuilder patternBuilder = new StringBuilder ("^" );
147- Matcher variableMatcher = URI_VARIABLE_PATTERN .matcher (this .uriTemplate );
148- int lastEnd = 0 ;
149-
150- while (variableMatcher .find ()) {
151- // Append the literal part of the template, safely quoted
152- String textBefore = this .uriTemplate .substring (lastEnd , variableMatcher .start ());
153- patternBuilder .append (Pattern .quote (textBefore ));
154- // Append a capturing group for the variable itself
155- patternBuilder .append ("([^/]+?)" );
156- lastEnd = variableMatcher .end ();
157- }
158-
159- // Append any remaining literal text after the last variable
160- if (lastEnd < this .uriTemplate .length ()) {
161- patternBuilder .append (Pattern .quote (this .uriTemplate .substring (lastEnd )));
162- }
163-
164- patternBuilder .append ("$" );
145+ // characters like '?'.
146+ StringBuilder patternBuilder = new StringBuilder ("^" );
147+ Matcher variableMatcher = URI_VARIABLE_PATTERN .matcher (this .uriTemplate );
148+ int lastEnd = 0 ;
149+
150+ while (variableMatcher .find ()) {
151+ // Append the literal part of the template, safely quoted
152+ String textBefore = this .uriTemplate .substring (lastEnd , variableMatcher .start ());
153+ patternBuilder .append (Pattern .quote (textBefore ));
154+ // Append a capturing group for the variable itself
155+ patternBuilder .append ("([^/]+?)" );
156+ lastEnd = variableMatcher .end ();
157+ }
165158
166- // Check if the URI matches the regex
167- return Pattern .compile (patternBuilder .toString ()).matcher (uri ).matches ();
168- }
159+ // Append any remaining literal text after the last variable
160+ if (lastEnd < this .uriTemplate .length ()) {
161+ patternBuilder .append (Pattern .quote (this .uriTemplate .substring (lastEnd )));
162+ }
169163
164+ patternBuilder .append ("$" );
170165
166+ // Check if the URI matches the regex
167+ return Pattern .compile (patternBuilder .toString ()).matcher (uri ).matches ();
168+ }
171169
172170 @ Override
173171 public boolean isUriTemplate (String uri ) {
0 commit comments