Skip to content

fix: allow numeric header values#48

Closed
thilohaas wants to merge 1 commit intosinonjs:masterfrom
thilohaas:fix/numeric-header-values
Closed

fix: allow numeric header values#48
thilohaas wants to merge 1 commit intosinonjs:masterfrom
thilohaas:fix/numeric-header-values

Conversation

@thilohaas
Copy link
Copy Markdown

No description provided.

Comment thread lib/fake-xhr/index.js
function normalizeHeaderValue(value) {
// Ref: https://fetch.spec.whatwg.org/#http-whitespace-bytes
/*eslint no-control-regex: "off"*/
return value.replace(/^[\x09\x0A\x0D\x20]+|[\x09\x0A\x0D\x20]+$/g, "");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All header values should be strings. I think you might as well just handle the case by wrapping the value in String(value). When getting header values you should always get a string, anyway (so update the test as well). Any conversion to numbers in your code need to happen after header extraction. XHR can't know if the value is a number or string when sent on the wire, so this is client knowledge.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fatso83
Copy link
Copy Markdown
Contributor

fatso83 commented Jun 1, 2018

I changed my mind. Wrapping this in a string doesn't make sense, as the format is not decided. For instance, wrapping 1.0 will become "1", making the test fail with:

 `AssertionError: [assert.equals] 1 expected to be equal to 1.0`

We should throw on non-string vals

Header fields are colon-separated name-value pairs in clear-text string format, terminated by a carriage return (CR) and line feed (LF) character sequence

ref https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#General_format

@fatso83 fatso83 closed this Jun 1, 2018
fatso83 added a commit to fatso83/nise that referenced this pull request Jun 1, 2018
According to RFC7230, http fields have used to be text and new
headers should continue to do so, restricting the values to consist
of US-ASCII octets.

This test is not so strict, but we avoid a whole range of errors
by just checking if the value is a string.

Ref sinonjs#51 and sinonjs#48
fatso83 added a commit to fatso83/nise that referenced this pull request Jun 1, 2018
According to RFC7230, http fields have used to be text and new
headers should continue to do so, restricting the values to consist
of US-ASCII octets.

This test is not so strict, but we avoid a whole range of errors
by just checking if the value is a string.

Ref sinonjs#51, sinonjs#48 and https://tools.ietf.org/html/rfc7230#section-3.2.4
fatso83 added a commit that referenced this pull request Jun 1, 2018
According to RFC7230, http fields have used to be text and new
headers should continue to do so, restricting the values to consist
of US-ASCII octets.

This test is not so strict, but we avoid a whole range of errors
by just checking if the value is a string.

Ref #51, #48 and https://tools.ietf.org/html/rfc7230#section-3.2.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants