You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
encodeValue falls back to encodeURIComponent for every non-reserved operator, and encodeURIComponent deliberately leaves !'()* unescaped. RFC 6570 §3.2.1 (simple string expansion) expands everything outside ALPHA / DIGIT / "-" / "." / "_" / "~", so those five characters must be percent-encoded.
Same for ., /, ? and & expressions, since they all go through encodeValue:
newUriTemplate('{?q}').expand({q: 'a(b)'});// actual ?q=a(b) expected ?q=a%28b%29
Why it matters
Expansion output is what gets handed to a resource or tool URI, so a value containing those characters produces a URI that differs from what every other RFC 6570 implementation emits for the same input (uritemplate, python-uritemplate, @std/uri, …). Anything matching on the concrete URI — including this repo's own match() when a caller builds a URI elsewhere and matches it here — sees a different string. Parentheses and apostrophes are common in real values: file names, titles, search queries.
match() itself is unaffected: it returns the raw matched span and never decodes, so this change cannot desynchronise expand/match.
Where
packages/core-internal/src/shared/uriTemplate.ts, encodeValue — the non-reserved branch. The + and # branches are correct as they are: reserved expansion keeps sub-delims, so !'()* must stay literal there.
Fix
Percent-encode those five characters after encodeURIComponent, leaving the reserved branch alone. I have this written with tests (including a guard that {+var} and {#var} still keep the characters) and all 1861 core-internal tests plus eslint/prettier/tsgo passing, so say the word and I'll open the PR.
Note while I was in there: expand() on a multi-variable expression ignores the operator entirely and skips encoding ({.var,hello} with hello: 'Hello World!' gives value,Hello World! instead of .value.Hello%20World%21). That is a separate defect from #2166 (which is the match() side) and I have kept it out of the fix above to keep the diff reviewable — happy to file it separately if you'd like it tracked.
Activity