Skip to content

Commit ee65d0d

Browse files
JoostKbenlesh
authored andcommitted
fix(common): prevent repeated application of HttpParams mutations (#29045)
Previously, an instance of HttpParams would retain its list of mutations after they have been materialized as a result of a read operation. Not only does this unnecessarily hold onto memory, more importantly does it introduce a bug where branching of off a materialized instance would reconsider the set of mutations that had already been applied, resulting in repeated application of mutations. This commit fixes the bug by clearing the list of pending mutations after they have been materialized, such that they will not be considered once again for branched off instances. Fixes #20430 PR Close #29045
1 parent cd48a53 commit ee65d0d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/common/http/src/params.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export class HttpParams {
227227
}
228228
}
229229
});
230-
this.cloneFrom = null;
230+
this.cloneFrom = this.updates = null;
231231
}
232232
}
233233
}

packages/common/http/test/params_spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ import {HttpParams} from '@angular/common/http/src/params';
5353
const mutated = body.delete('a', '2').delete('a', '4');
5454
expect(mutated.getAll('a')).toEqual(['1', '3', '5']);
5555
});
56+
57+
it('should not repeat mutations that have already been materialized', () => {
58+
const body = new HttpParams({fromString: 'a=b'});
59+
const mutated = body.append('a', 'c');
60+
expect(mutated.toString()).toEqual('a=b&a=c');
61+
const mutated2 = mutated.append('c', 'd');
62+
expect(mutated.toString()).toEqual('a=b&a=c');
63+
expect(mutated2.toString()).toEqual('a=b&a=c&c=d');
64+
});
5665
});
5766

5867
describe('read operations', () => {

0 commit comments

Comments
 (0)