fix(http): ignore question mark when params are parsed (#40610)
This commit adds a fix where params will ignore questions marks when parsed. Fixes #28722 PR Close #40610
This commit is contained in:
parent
3b7d2ca179
commit
f340a5b9f2
|
@ -73,7 +73,10 @@ export class HttpUrlEncodingCodec implements HttpParameterCodec {
|
|||
function paramParser(rawParams: string, codec: HttpParameterCodec): Map<string, string[]> {
|
||||
const map = new Map<string, string[]>();
|
||||
if (rawParams.length > 0) {
|
||||
const params: string[] = rawParams.split('&');
|
||||
// The `window.location.search` can be used while creating an instance of the `HttpParams` class
|
||||
// (e.g. `new HttpParams({ fromString: window.location.search })`). The `window.location.search`
|
||||
// may start with the `?` char, so we strip it if it's present.
|
||||
const params: string[] = rawParams.replace(/^\?/, '').split('&');
|
||||
params.forEach((param: string) => {
|
||||
const eqIdx = param.indexOf('=');
|
||||
const [key, val]: string[] = eqIdx == -1 ?
|
||||
|
|
|
@ -21,6 +21,19 @@ import {HttpParams} from '@angular/common/http/src/params';
|
|||
expect(body.getAll('a')).toEqual(['b']);
|
||||
expect(body.getAll('c')).toEqual(['d', 'e']);
|
||||
});
|
||||
|
||||
it('should ignore question mark in a url', () => {
|
||||
const body = new HttpParams({fromString: '?a=b&c=d&c=e'});
|
||||
expect(body.getAll('a')).toEqual(['b']);
|
||||
expect(body.getAll('c')).toEqual(['d', 'e']);
|
||||
});
|
||||
|
||||
it('should only remove question mark at the beginning of the params', () => {
|
||||
const body = new HttpParams({fromString: '?a=b&c=d&?e=f'});
|
||||
expect(body.getAll('a')).toEqual(['b']);
|
||||
expect(body.getAll('c')).toEqual(['d']);
|
||||
expect(body.getAll('?e')).toEqual(['f']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('lazy mutation', () => {
|
||||
|
|
Loading…
Reference in New Issue