Skip to content

Commit

Permalink
[core-http] trim leading and trailing whitespace from header values (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremymeng committed Nov 11, 2023
1 parent 5d52e1e commit 4238888
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions sdk/core/core-http/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

### Other Changes

- Trim leading and trailing whitespace from header values.

## 3.0.3 (2023-08-31)

### Other Changes
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-http/src/httpHeaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class HttpHeaders implements HttpHeadersLike {
public set(headerName: string, headerValue: string | number): void {
this._headersMap[getHeaderKey(headerName)] = {
name: headerName,
value: headerValue.toString(),
value: headerValue.toString().trim(),
};
}

Expand Down
18 changes: 18 additions & 0 deletions sdk/core/core-http/test/httpHeadersTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,22 @@ describe("HttpHeaders", () => {
assert.include(rawHeaders, { [pair.name]: pair.value });
});
});

it("should remove leading and trailing whitespace in values", () => {
const rawHeaders = {
withLeadingWhitespace: " value1",
withTrailingWhitespace: "value2 ",
withLeadingAndTrialingWhitespace: " value3 ",
};
const headers = new HttpHeaders(rawHeaders);

const expected = {
withLeadingWhitespace: "value1",
withTrailingWhitespace: "value2",
withLeadingAndTrialingWhitespace: "value3",
};
for (const {name, value} of headers.headersArray()) {
assert.include(expected, { [name]: value });
}
});
});

0 comments on commit 4238888

Please sign in to comment.