Skip to content

Commit ae549d8

Browse files
committed
Update encodeFormDataQuote
1 parent cc4d520 commit ae549d8

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

packages/components/src/internal/url/utils.test.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,22 @@ describe('encodeFormDataQuote', () => {
88
});
99

1010
test('no relevant special character', () => {
11-
expect(encodeFormDataQuote('a')).toBe('a')
11+
expect(encodeFormDataQuote('a')).toBe('a');
1212
expect(encodeFormDataQuote('$')).toBe('$');
13-
expect(encodeFormDataQuote('%')).toBe('%');
14-
expect(encodeFormDataQuote('%2522')).toBe('%2522');
13+
expect(encodeFormDataQuote('9')).toBe('9');
14+
expect(encodeFormDataQuote('[a]')).toBe('[a]');
1515
});
1616

1717
test('encoded', () => {
18-
expect(encodeFormDataQuote('"')).toBe('%22')
19-
expect(encodeFormDataQuote('""')).toBe('%22%22');
20-
expect(encodeFormDataQuote('"22')).toBe('%2222');
21-
expect(encodeFormDataQuote('"a"')).toBe('%22a%22');
22-
expect(encodeFormDataQuote('a%22')).toBe('a%2522');
23-
expect(encodeFormDataQuote('"a%22')).toBe('%22a%2522');
24-
expect(encodeFormDataQuote('"a%222')).toBe('%22a%25222');
18+
expect(encodeFormDataQuote('"')).toBe('%_%22');
19+
expect(encodeFormDataQuote('%')).toBe('%_%25');
20+
expect(encodeFormDataQuote('%_beep')).toBe('%_%25_beep');
21+
expect(encodeFormDataQuote('""')).toBe('%_%22%22');
22+
expect(encodeFormDataQuote('"22')).toBe('%_%2222');
23+
expect(encodeFormDataQuote('"a"')).toBe('%_%22a%22');
24+
expect(encodeFormDataQuote('a%22')).toBe('%_a%2522');
25+
expect(encodeFormDataQuote('"a%22')).toBe('%_%22a%2522');
26+
expect(encodeFormDataQuote('"a%222')).toBe('%_%22a%25222');
2527
});
2628
});
2729

packages/components/src/internal/url/utils.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ export function encodeListResolverPath(containerPath: string): string {
66
return ['$CPS', containerPath?.toLowerCase(), '$CPE'].join('');
77
}
88

9-
// Issue 52925, 52119
9+
// Issue 52925, Issue 52119, Issue 54218
1010
export function encodeFormDataQuote(key: string): string {
11-
if (!key)
12-
return key;
13-
// need to replace %22, before replacing " to %22
14-
return key?.replaceAll('%22', '%2522').replaceAll('"', '%22');
11+
if (!key || !/[\\"%]/.test(key)) return key;
12+
return '%_' + encodeURIComponent(key);
1513
}
1614

1715
export function getIntegerSearchParam(searchParams: URLSearchParams, paramName: string): number {

0 commit comments

Comments
 (0)