fix(router): fix error when calling ParamMap.get function (#31599)
fix this.params.hasOwnProperty is not a function in case of creating an object using Object.create() PR Close #31599
This commit is contained in:
parent
80d0067048
commit
2170ea270a
|
@ -74,7 +74,7 @@ class ParamsAsMap implements ParamMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
has(name: string): boolean {
|
has(name: string): boolean {
|
||||||
return this.params.hasOwnProperty(name);
|
return Object.prototype.hasOwnProperty.call(this.params, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
get(name: string): string|null {
|
get(name: string): string|null {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {convertToParamMap, ParamMap} from '../src/shared';
|
import {convertToParamMap, ParamMap, Params} from '../src/shared';
|
||||||
|
|
||||||
describe('ParamsMap', () => {
|
describe('ParamsMap', () => {
|
||||||
it('should returns whether a parameter is present', () => {
|
it('should returns whether a parameter is present', () => {
|
||||||
|
@ -42,4 +42,14 @@ describe('ParamsMap', () => {
|
||||||
const map = convertToParamMap({});
|
const map = convertToParamMap({});
|
||||||
expect(map.getAll('name')).toEqual([]);
|
expect(map.getAll('name')).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not error when trying to call ParamMap.get function using an object created with Object.create() function',
|
||||||
|
() => {
|
||||||
|
const objectToMap: Params = Object.create(null);
|
||||||
|
objectToMap['single'] = 's';
|
||||||
|
objectToMap['multiple'] = ['m1', 'm2'];
|
||||||
|
const paramMaps: ParamMap = convertToParamMap(objectToMap);
|
||||||
|
expect(() => paramMaps.get('single')).not.toThrow();
|
||||||
|
expect(paramMaps.get('single')).toEqual('s');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue