fix(router): correct the segment parsing so it won't break on ampersand (#23684)

PR Close #23684
This commit is contained in:
Jason Aden 2018-05-03 12:03:13 -07:00 committed by Igor Minar
parent 858e48a794
commit 553a680817
2 changed files with 9 additions and 1 deletions

View File

@ -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] : '';

View File

@ -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', () => {