Skip to content

Commit ee816e1

Browse files
DW8ReaperAndrewKushnir
authored andcommitted
revert "fixup! fix(router): fix = not parsed in router segment name" (#47332)
This reverts commit 2279f4d4620eba083a9832ed096890b69a25ec42. Reverting that commit based off PR feedback that this change should only affect the parsing of sergments and node encoding of the url PR Close #47332
1 parent 748c33c commit ee816e1

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

packages/core/test/bundling/router/bundle.golden_symbols.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,9 +1682,6 @@
16821682
{
16831683
"name": "match"
16841684
},
1685-
{
1686-
"name": "matchMatrixParamSegments"
1687-
},
16881685
{
16891686
"name": "matchSegments"
16901687
},

packages/router/src/url_tree.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,7 @@ function encodeUriString(s: string): string {
445445
.replace(/%40/g, '@')
446446
.replace(/%3A/gi, ':')
447447
.replace(/%24/g, '$')
448-
.replace(/%2C/gi, ',')
449-
.replace(/%3D/gi, '=');
448+
.replace(/%2C/gi, ',');
450449
}
451450

452451
/**
@@ -521,7 +520,7 @@ function matchSegments(str: string): string {
521520
}
522521

523522
const MATRIX_PARAM_SEGMENT_RE = /^[^\/()?;=#]+/;
524-
function matchMatrixParamSegments(str: string): string {
523+
function matchMatrixKeySegments(str: string): string {
525524
const match = str.match(MATRIX_PARAM_SEGMENT_RE);
526525
return match ? match[0] : '';
527526
}
@@ -631,14 +630,14 @@ class UrlParser {
631630
}
632631

633632
private parseParam(params: {[key: string]: string}): void {
634-
const key = matchMatrixParamSegments(this.remaining);
633+
const key = matchMatrixKeySegments(this.remaining);
635634
if (!key) {
636635
return;
637636
}
638637
this.capture(key);
639638
let value: any = '';
640639
if (this.consumeOptional('=')) {
641-
const valueMatch = matchMatrixParamSegments(this.remaining);
640+
const valueMatch = matchSegments(this.remaining);
642641
if (valueMatch) {
643642
value = valueMatch;
644643
this.capture(value);

packages/router/test/url_serializer.spec.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ describe('url serializer', () => {
5656
expect(tree.root.children.primary.segments[2].path).toEqual('=');
5757
});
5858

59+
it('should parse segments with matrix parameter values containing an =', () => {
60+
const tree = url.parse('/path/to/something;query=file=test;query2=test2');
61+
expect(tree.root.children.primary.segments[2].path).toEqual('something');
62+
expect(tree.root.children.primary.segments[2].parameterMap.keys).toHaveSize(2);
63+
expect(tree.root.children.primary.segments[2].parameterMap.get('query')).toEqual('file=test');
64+
expect(tree.root.children.primary.segments[2].parameterMap.get('query2')).toEqual('test2');
65+
});
66+
5967
it('should parse top-level nodes with only secondary segment', () => {
6068
const tree = url.parse('/(left:one)');
6169

@@ -266,9 +274,9 @@ describe('url serializer', () => {
266274
});
267275

268276
it('should encode query params leaving sub-delimiters intact', () => {
269-
const percentChars = '/?#&+[] ';
270-
const percentCharsEncoded = '%2F%3F%23%26%2B%5B%5D%20';
271-
const intactChars = '!$\'()*,;:=';
277+
const percentChars = '/?#&+=[] ';
278+
const percentCharsEncoded = '%2F%3F%23%26%2B%3D%5B%5D%20';
279+
const intactChars = '!$\'()*,;:';
272280
const params = percentChars + intactChars;
273281
const paramsEncoded = percentCharsEncoded + intactChars;
274282
const mixedCaseString = 'sTrInG';
@@ -339,9 +347,9 @@ describe('url serializer', () => {
339347
const unreserved = `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~`;
340348

341349
it('should encode a minimal set of special characters in queryParams', () => {
342-
const notEncoded = unreserved + `:@!$'*,();=`;
343-
const encode = ` +%&#[]/?`;
344-
const encoded = `%20%2B%25%26%23%5B%5D%2F%3F`;
350+
const notEncoded = unreserved + `:@!$'*,();`;
351+
const encode = ` +%&=#[]/?`;
352+
const encoded = `%20%2B%25%26%3D%23%5B%5D%2F%3F`;
345353

346354
const parsed = url.parse('/foo');
347355

@@ -364,20 +372,21 @@ describe('url serializer', () => {
364372

365373
it('should encode minimal special characters plus parens and semi-colon in matrix params',
366374
() => {
367-
const notEncoded = unreserved + `:@!$'*,&=`;
368-
const encode = ` /%#()[];?+`;
369-
const encoded = `%20%2F%25%23%28%29%5B%5D%3B%3F%2B`;
375+
const notEncoded = unreserved + `:@!$'*,&`;
376+
const encode = ` /%=#()[];?+`;
377+
const encoded = `%20%2F%25%3D%23%28%29%5B%5D%3B%3F%2B`;
370378

371379
const parsed = url.parse('/foo');
372380

373381
parsed.root.children[PRIMARY_OUTLET].segments[0].parameters = {notEncoded, encode};
382+
374383
expect(url.serialize(parsed)).toBe(`/foo;notEncoded=${notEncoded};encode=${encoded}`);
375384
});
376385

377386
it('should encode special characters in the path the same as matrix params', () => {
378-
const notEncoded = unreserved + `:@!$'*,&=`;
379-
const encode = ` /%#()[];?+`;
380-
const encoded = `%20%2F%25%23%28%29%5B%5D%3B%3F%2B`;
387+
const notEncoded = unreserved + `:@!$'*,&`;
388+
const encode = ` /%=#()[];?+`;
389+
const encoded = `%20%2F%25%3D%23%28%29%5B%5D%3B%3F%2B`;
381390

382391
const parsed = url.parse('/foo');
383392

@@ -386,14 +395,6 @@ describe('url serializer', () => {
386395
expect(url.serialize(parsed)).toBe(`/${notEncoded}${encoded}`);
387396
});
388397

389-
it('should preserve = when encoding segments', () => {
390-
const testUrl = '/foo===bar';
391-
392-
const parsed = url.parse(testUrl);
393-
394-
expect(url.serialize(parsed)).toBe(testUrl);
395-
});
396-
397398
it('should correctly encode ampersand in segments', () => {
398399
const testUrl = '/parent&child';
399400

0 commit comments

Comments
 (0)