Skip to content

Commit df31e14

Browse files
committed
Apply auto-formatting fixes
1 parent 99623be commit df31e14

File tree

2 files changed

+30
-31
lines changed

2 files changed

+30
-31
lines changed

mcp-core/src/main/java/io/modelcontextprotocol/util/DefaultMcpUriTemplateManager.java

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {

mcp-core/src/test/java/io/modelcontextprotocol/McpUriTemplateManagerTests.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,13 @@ void shouldMatchUriAgainstTemplatePattern() {
9494
assertFalse(uriTemplateManager.matches("/api/users/123/comments/456"));
9595
}
9696

97-
@Test
98-
void shouldMatchUriWithQueryParameters() {
99-
String templateWithQuery = "file://name/search?={search}";
100-
var uriTemplateManager = this.uriTemplateFactory.create(templateWithQuery);
101-
102-
assertTrue(uriTemplateManager.matches("file://name/search?=abcd"),
103-
"Should correctly match a URI containing query parameters.");
104-
}
97+
@Test
98+
void shouldMatchUriWithQueryParameters() {
99+
String templateWithQuery = "file://name/search?={search}";
100+
var uriTemplateManager = this.uriTemplateFactory.create(templateWithQuery);
101+
102+
assertTrue(uriTemplateManager.matches("file://name/search?=abcd"),
103+
"Should correctly match a URI containing query parameters.");
104+
}
105+
105106
}

0 commit comments

Comments
 (0)