fix(router): correct the segment parsing so it won't break on ampersand (#23684)
PR Close #23684
This commit is contained in:
parent
858e48a794
commit
553a680817
|
@ -406,7 +406,7 @@ function serializeQueryParams(params: {[key: string]: any}): string {
|
|||
return strParams.length ? `?${strParams.join("&")}` : '';
|
||||
}
|
||||
|
||||
const SEGMENT_RE = /^[^\/()?;=&#]+/;
|
||||
const SEGMENT_RE = /^[^\/()?;=#]+/;
|
||||
function matchSegments(str: string): string {
|
||||
const match = str.match(SEGMENT_RE);
|
||||
return match ? match[0] : '';
|
||||
|
|
|
@ -359,6 +359,14 @@ describe('url serializer', () => {
|
|||
|
||||
expect(url.serialize(parsed)).toBe(`/${notEncoded}${encoded}`);
|
||||
});
|
||||
|
||||
it('should correctly encode ampersand in segments', () => {
|
||||
const testUrl = '/parent&child';
|
||||
|
||||
const parsed = url.parse(testUrl);
|
||||
|
||||
expect(url.serialize(parsed)).toBe(testUrl);
|
||||
});
|
||||
});
|
||||
|
||||
describe('error handling', () => {
|
||||
|
|
Loading…
Reference in New Issue