fix(router): avoid freezing queryParams in-place (#22663)
The recognizer code used to call Object.freeze() on queryParams before using them to construct ActivatedRoutes, with the intent being to help avoid common invalid usage. Unfortunately, Object.freeze() works in-place, so this was also freezing the queryParams on the actual UrlTree object, making it more difficult to manipulate UrlTrees in things like UrlHandlingStrategy. This change simply shallow-copies the queryParams before freezing them. Fixes #22617 PR Close #22663
This commit is contained in:

committed by
Igor Minar

parent
8733843c11
commit
3d8799b3a2
@ -748,6 +748,14 @@ describe('recognize', () => {
|
||||
expect(Object.isFrozen(s.root.queryParams)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not freeze UrlTree query params', () => {
|
||||
const url = tree('a?q=11');
|
||||
recognize(RootComponent, [{path: 'a', component: ComponentA}], url, 'a?q=11')
|
||||
.subscribe((s: RouterStateSnapshot) => {
|
||||
expect(Object.isFrozen(url.queryParams)).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('fragment', () => {
|
||||
|
Reference in New Issue
Block a user