fix(router): Allow question marks in query param values (#31187)
According to the URI spec, question mark characters are valid in query data, so these should accepted by the param parsing. See https://tools.ietf.org/html/rfc3986#section-3.4 Fixes #31116 BREAKING CHANGE: The default url serializer would previously drop everything after and including a question mark in query parameters. That is, for a navigation to `/path?q=hello?&other=123`, the query params would be parsed to just `{q: 'hello'}`. This is incorrect because the URI spec allows for question mark characers in query data. This change will now correctly parse the params for the above example to be `{v: 'hello?', other: '123'}`. PR Close #31187
This commit is contained in:
parent
d8690d867c
commit
784671597e
|
@ -523,7 +523,7 @@ function matchQueryParams(str: string): string {
|
|||
return match ? match[0] : '';
|
||||
}
|
||||
|
||||
const QUERY_PARAM_VALUE_RE = /^[^?&#]+/;
|
||||
const QUERY_PARAM_VALUE_RE = /^[^&#]+/;
|
||||
// Return the value of the query param at the start of the string or an empty string
|
||||
function matchUrlQueryParamValue(str: string): string {
|
||||
const match = str.match(QUERY_PARAM_VALUE_RE);
|
||||
|
|
|
@ -26,6 +26,11 @@ describe('UrlTree', () => {
|
|||
'k/(a;b)': 'c',
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow question marks in query param values', () => {
|
||||
const tree = serializer.parse('/path/to?first=http://foo/bar?baz=true&second=123');
|
||||
expect(tree.queryParams).toEqual({'first': 'http://foo/bar?baz=true', 'second': '123'});
|
||||
});
|
||||
});
|
||||
|
||||
describe('containsTree', () => {
|
||||
|
|
Loading…
Reference in New Issue