Skip to content

fix(core): reject blank URIs and empty template captures - #1117

Open
liyifan9642-creator wants to merge 1 commit into
modelcontextprotocol:mainfrom
liyifan9642-creator:fix/1085-blank-resource-uri
Open

liyifan9642-creator wants to merge 1 commit into
modelcontextprotocol:mainfrom
liyifan9642-creator:fix/1085-blank-resource-uri

Conversation

@liyifan9642-creator

Copy link
Copy Markdown

Summary

Fixes #1085.

PathSegmentTemplateMatcher.match("") currently matches {id} with id = "", allowing a blank resources/read URI to reach a template handler.

  • Reject blank incoming URIs after the existing length check.
  • Reject empty variable captures without rejecting empty literal segments, such as those in file:///report.txt.
  • Update the matching contract and replace the test that pinned empty-URI captures.
  • Add regression coverage for blank URIs, empty variable segments, valid file URIs, percent-encoded whitespace, and the literal root path.
  • Add an in-memory client/server test verifying that blank resource URIs return RESOURCE_NOT_FOUND and do not invoke the template handler.

No public API or tracked build configuration changes.

Verification

Before the production fix, the matcher tests failed in the two expected cases, and the new client/server regression test failed because no exception was thrown.

After the fix:

  • :kotlin-sdk-core:jvmTest: 258 tests passed.
  • :integration-test:jvmTest --tests '*ServerResourceTemplateTest': 9 tests passed.
  • :kotlin-sdk-core:ktlintCheck and :integration-test:ktlintCheck: passed.
  • :kotlin-sdk-core:checkKotlinAbi: passed, including the multiplatform ABI comparison.
  • git diff --check: passed.

The core Detekt task completed successfully but reported 107 compiler errors during analysis, so its type-resolved analysis accuracy was limited. Local validation used an external Gradle init script to resolve plugins through a reachable mirror; dependency versions and tracked build files were unchanged.

@jetbrains-air jetbrains-air Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

An empty URI matches a single-variable resource template

1 participant