Skip to content

Commit 7c34c12

Browse files
committed
refactor: simplify explode split since regex guarantees leading separator
The explode capture pattern ((?:SEP body)*?) means non-empty captures always start with the separator, so split()[0] is always empty. The defensive if-check was a dead branch; slice unconditionally instead.
1 parent a8f488e commit 7c34c12

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/mcp/shared/uri_template.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -522,14 +522,11 @@ def _extract_path(m: re.Match[str], variables: Sequence[Variable]) -> dict[str,
522522
continue
523523
segments: list[str] = []
524524
prefix = f"{var.name}="
525-
# Splitting on the separator yields an empty first item from
526-
# the leading prefix. Strip only that one; subsequent empty
527-
# items are legitimate empty values ({/path*} with ["a","","c"]
528-
# expands to /a//c and must round-trip).
529-
items = raw.split(spec.separator)
530-
if items and not items[0]:
531-
items = items[1:]
532-
for seg in items:
525+
# The explode regex ((?:SEP body)*?) guarantees non-empty
526+
# captures start with the separator, so split()[0] is always
527+
# "". Slice it off; subsequent empties are legitimate values
528+
# ({/path*} with ["a","","c"] expands to /a//c).
529+
for seg in raw.split(spec.separator)[1:]:
533530
if spec.named:
534531
# Named explode emits name=value per item (or bare
535532
# name for ; with empty value). Validate the name

0 commit comments

Comments
 (0)