fix(common): tolerate invalid percent-encoding in HttpUrlEncodingCodec - #69042
rootvector2 wants to merge 2 commits into
Conversation
| function tryDecodeURIComponent(value: string): string { | ||
| try { | ||
| return decodeURIComponent(value); | ||
| } catch { | ||
| return value; | ||
| } |
There was a problem hiding this comment.
As mentionned in #69061, can we have a private export of tryDecodeURIComponent in core to private duplicate implementations of this behavior.
There was a problem hiding this comment.
done — added ɵtryDecodeURIComponent as a private export in core and routed HttpUrlEncodingCodec through it. i'll rebase the upgrade/router/cookie PRs onto it so they drop their own copies.
| * @param value potential URI component to decode. | ||
| * @returns the decoded URI if it can be decoded, otherwise `undefined`. | ||
| */ | ||
| export function tryDecodeURIComponent(value: string): string | undefined { |
There was a problem hiding this comment.
NIT: maybe instead of tryDecodeURIComponent and returning undefined, we can go with decodeURIComponentSafe and instead of returning undefined return the original value
There was a problem hiding this comment.
done — renamed to decodeURIComponentSafe and it returns the original value on failure, so the callers drop the ?? value.
|
That being said, I wonder if the risk is too big for this change to land. |
Hoist the decode fallback into a private `ɵdecodeURIComponentSafe` export in core and route `HttpUrlEncodingCodec` through it, so the codec packages share a single implementation instead of duplicating it.
55d8c70 to
8d06231
Compare
|
the mixed-encoding limitation from #69049 applies here too: a value like the difference from the router is theres no navigation/validation gate here. if you still feel the risk outweighs that, im fine closing it. |
|
any update? |


Noticed
HttpUrlEncodingCodec.decodeKey/decodeValuecalldecodeURIComponentdirectly, andHttpParamsfeeds them straight from itsfromStringoption (the class docs suggest passingwindow.location.search). A stray%in the query, e.g.?a=100%done, is a valid query character but makesdecodeURIComponentthrow aURIErrorthat escapes theHttpParamsconstructor. Decode in a try/catch and fall back to the raw value, leaving valid escapes decoded as before.