Skip to content

Commit 421609c

Browse files
committed
fix: round-trip dotted URI template values
1 parent 77001c9 commit 421609c

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

‎src/mcp/shared/uri_template.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,12 @@ def _scan_suffix(
997997
stops = _STOP_CHARS[var.operator]
998998
prev = atoms[i - 1] if i > 0 else None
999999

1000+
# A dotted variable immediately following a literal has an unambiguous
1001+
# boundary: the operator's dot is the separator. Keep additional dots in
1002+
# the value so expansions such as `file{.ext}` with `ext="tar.gz"` round-trip.
1003+
if var.operator == "." and isinstance(prev, _Lit) and (i < 2 or isinstance(atoms[i - 2], _Lit)):
1004+
stops = "/?#"
1005+
10001006
if atom.ifemp:
10011007
# ;name or ;name=value. The preceding _Lit is ";name".
10021008
# Try empty first: if the lit ends at pos the value is

‎tests/shared/test_uri_template.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,7 @@ def test_match_explode_encoded_separator_in_segment():
838838
("file://docs/{+path}", {"path": "src/main.py"}),
839839
("search{?q,lang}", {"q": "mcp", "lang": "en"}),
840840
("file{.ext}", {"ext": "txt"}),
841+
("file{.ext}", {"ext": "tar.gz"}),
841842
("/files{/path*}", {"path": ["a", "b", "c"]}),
842843
("{var}", {"var": "hello world"}),
843844
("item{;id}", {"id": "42"}),

0 commit comments

Comments
 (0)