Skip to content

fix: reject path template holes that share a segment with literal text#132

Open
OmarAlJarrah wants to merge 1 commit into
mainfrom
b1-pathtemplate-resegment
Open

fix: reject path template holes that share a segment with literal text#132
OmarAlJarrah wants to merge 1 commit into
mainfrom
b1-pathtemplate-resegment

Conversation

@OmarAlJarrah

Copy link
Copy Markdown
Member

Summary

  • PathTemplate.parse never required a {hole} to sit at a / boundary, so a literal prefix or suffix sharing a path segment with a hole (e.g. /reports/{id}.json or v{version}) got silently re-segmented when the URL was built: BindingExecutor's appendTokenSegments splits every Literal token on / and adds every Hole token as its own segment, regardless of whether it was adjacent to literal text in the template.
  • @PathTemplate frames itself as a "Go-style path template", and net/http.ServeMux wildcards must occupy a full path segment, so the fix rejects a boundary violation at parse time (fail fast) rather than trying to keep same-segment literal/hole runs together during composition. A hole is still allowed to sit directly against another hole with no literal between them ({a}{b}), since neither side can be split.
  • Documented the new constraint on the @PathTemplate KDoc.

Test plan

  • ./gradlew :kuri-bind:jvmTest — added regression tests reproducing both issue examples (/reports/{id}.json with id=5, v{version} with version=2) at both the PathTemplate.parse level and end-to-end through BindingExecutor; confirmed they failed before the fix and pass after.
  • ./gradlew :kuri-bind:ktlintCheck
  • ./gradlew :kuri-bind:detekt
  • ./gradlew :kuri-bind:apiCheck (no public API shape change — kuri-bind is JVM-only, so no jsNodeTest/native leg applies here)

Closes #82

PathTemplate.parse never required a {hole} to sit at a "/" boundary, so
a literal prefix or suffix sharing a path segment with a hole (e.g.
"/reports/{id}.json" or "v{version}") got silently re-segmented when
the URL was built: BindingExecutor's appendTokenSegments splits every
Literal token on "/" and adds every Hole token as its own segment,
independent of whether they were adjacent in the template.

@PathTemplate documents itself as a "Go-style path template", and
net/http.ServeMux wildcards must occupy a full path segment, so fail
fast at parse time instead: a hole whose neighboring literal doesn't
carry a "/" at the shared edge is now rejected with KuriBindException.
Adjacent holes with no literal between them (e.g. "{a}{b}") are still
allowed, since neither can be split.

Closes #82
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.

kuri-bind: @PathTemplate holes sharing a path segment with literal text are silently re-segmented

1 participant