| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| expect(fourth.has('foo')).toEqual(false); | ||
| }); | ||
|
|
||
| it('should delete only the exact matching string value', () => { |
There was a problem hiding this comment.
Looking into HttpHeaders a bit more, I found some cases that weren't being handled correctly, so I added another commit to address this.
Sorry, something went wrong.
|
I believe this test should be passing, but doesn't. it('should delete only the exact matching string value, not substrings', () => {
const headers = new HttpHeaders({
'X-Scopes': ['tenant:alpha', 'tenant:alpha:archive'],
});
// We only want to delete the 'tenant:alpha:archive' value
const updated = headers.delete('X-Scopes', 'tenant:alpha:archive');
expect(updated.getAll('X-Scopes')).toEqual(['tenant:alpha']);
});Potentially we should also have this one to pass: it('should treat an empty string as a specific value to delete', () => {
const headers = new HttpHeaders({ foo: ['', 'bar'] });
// We only want to delete the empty string
const updated = headers.delete('foo', '');
// causing the entire 'foo' header key to be wiped out.
expect(updated.getAll('foo')).toEqual(['bar']);
}); |
Sorry, something went wrong.
These tests are actually here in this commit 7290fe9 (this commit) and they pass in local |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM.
Not sure why this was logged with GVP.
Sorry, something went wrong.
Since the immutability contract isn't respected during SSR, headers can be mutated unexpectedly, adding or removing scopes. One possible case is TransferCache excluding a sensitive header, but because the contract isn't honored, it isn't recognized and ends up in the final HTML. I can't confidently assess the severity, but given this, I think it might at least be worth backporting ? |
Sorry, something went wrong.
There was a problem hiding this comment.
AGENT: Thanks for this fix! I have left a minor inline suggestion for your consideration.
Sorry, something went wrong.
|
AGENT: I have re-reviewed this PR and found two issues regarding the implementation of the fix: Issue 1: Inconsistent deletion behavior between HttpHeaders and HttpParamsThe PR correctly refactors HttpHeaders to fix a substring matching bug when deleting values. By using filter(), it successfully removes all occurrences of the targeted value if it was added multiple times. Issue 2: Eager O(N) memory allocation (Performance Regression)To preserve immutability, the PR fixes the shared array mutation bug by eagerly slicing every single array in the map during init(): for (const [key, values] of other.headers.entries()) {
this.headers.set(key, values.slice());
// ...
}This forces an O(N) copy of the entire header/parameter map into memory upon initialization, regardless of how many keys are actually being modified. A more performant copy-on-write approach would be to leave the arrays shared initially, and only invoke .slice() locally inside applyUpdate for the specific array that is actively being mutated (e.g., before base.push() or base.splice()). |
Sorry, something went wrong.
Prevent lazy HttpHeaders and HttpParams clones from reusing value arrays owned by a materialized source. Append and value-specific delete operations previously mutated those shared arrays, violating the immutable API contract and allowing request metadata to bleed into later requests. Share value arrays until an update mutates a specific header or parameter, then copy only that array. Cover the affected append and delete paths with regression tests that materialize the source first.
Normalize value-specific HttpHeaders deletions before filtering. The string overload previously used String#indexOf and removed shorter values contained within the requested deletion value, potentially widening outgoing request metadata. Preserve delete-all behavior only when no value is supplied, and cover string, array, and empty-string deletion.
| const body = new HttpParams({fromString: 'a=false&a=true&a=false'}); | ||
| const mutated = body.delete('a', false); | ||
| expect(mutated.getAll('a')).toEqual(['true', 'false']); | ||
| expect(mutated.getAll('a')).toEqual(['true']); |
There was a problem hiding this comment.
Issue 1: Inconsistent deletion behavior between HttpHeaders and HttpParams
Apparently, we previously had a test that considered this expected; I just updated it.
Sorry, something went wrong.
There was a problem hiding this comment.
if we had a test I would prefer that we revert the change. The agent might have missed that detail.
Sorry, something went wrong.
There was a problem hiding this comment.
Done , I just removed it, although this is going to be a bit strange. Should we possibly open an issue to map this behavior?
Sorry, something went wrong.
|
This PR was merged into the repository. The changes were merged into the following branches: |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Prevent lazy HttpHeaders and HttpParams clones from reusing value arrays owned by a materialized source. Append and value-specific delete operations previously mutated those shared arrays, violating the immutable API contract and allowing request metadata to bleed into later requests.
Copy each value array during clone materialization and cover the affected append and delete paths with regression tests that materialize the source first.
More context https://issuetracker.google.com/issues/533607148