Skip to content

Follow spec on Headers to throw TypeError, add tests for Headers - #85

Merged
josh merged 2 commits into
JakeChampion:masterfrom
itsmattking:master
Feb 2, 2015
Merged

josh merged 2 commits into
JakeChampion:masterfrom
itsmattking:master

Conversation

@itsmattking

Copy link
Copy Markdown
Contributor

No description provided.

@dgraham

dgraham commented Jan 29, 2015

Copy link
Copy Markdown
Contributor

Chrome and Firefox nightlies currently accept non-String keys and values:

h = new Headers()
h.append(12, 42)
// => undefined
h.has(12)
// => true

@annevk Is this correct behavior, or should a TypeError be thrown for non-String headers?

@josh

josh commented Jan 29, 2015

Copy link
Copy Markdown
Contributor

Nice!

It looks like Chrome native fetch() doesn't throw on bad types, but just toString()s them.

screen shot 2015-01-29 at 11 59 07 am

Think you can help report a bug on the Chrome issue tracker for this?

@domenic

domenic commented Jan 29, 2015

Copy link
Copy Markdown

The spec says to convert to string, not to throw.

@domenic

domenic commented Jan 29, 2015

Copy link
Copy Markdown

@josh

josh commented Jan 29, 2015

Copy link
Copy Markdown
Contributor

@domenic

domenic commented Jan 29, 2015

Copy link
Copy Markdown

Yes, they definitely are.

@itsmattking

Copy link
Copy Markdown
Contributor Author

According to this it should throw TypeError https://fetch.spec.whatwg.org/#headers-class

@domenic

domenic commented Jan 29, 2015

Copy link
Copy Markdown

Which step?

@itsmattking

Copy link
Copy Markdown
Contributor Author

Example:

To append a name/value (name/value) pair to a Headers object (headers), run these steps:
If name is not a name or value is not a value, throw a TypeError.

It's listed under each method definition.

@domenic

domenic commented Jan 29, 2015

Copy link
Copy Markdown

Right, so you should be testing whether they match https://tools.ietf.org/html/rfc2616#section-4.2, not doing a type-test. They're already converted to strings since the method signature contains ByteString/DOMString/USVString (depending on the method).

@itsmattking

Copy link
Copy Markdown
Contributor Author

It's not clear to me what it should match based on the RFC, any ideas? Or is this check not really necessary?

@annevk

annevk commented Jan 29, 2015

Copy link
Copy Markdown

@dgraham that might not necessarily be a bug if both methods stringify. If the value of "12" is not a string you found a bug.

@domenic

domenic commented Jan 29, 2015

Copy link
Copy Markdown

@MattKing17 you quoted

To append a name/value (name/value) pair to a Headers object (headers), run these steps:
If name is not a name or value is not a value, throw a TypeError.

The "name" link says

A name is a case-insensitive byte sequence that matches the field-name token production.

The "field-name" link links to the RFC which defines

field-name     = token

@itsmattking

Copy link
Copy Markdown
Contributor Author

Thanks @domenic, that makes sense now. Updated the PR with field name checks to match the RFC, and removed string type checking and put in toString calls instead.

@itsmattking

Copy link
Copy Markdown
Contributor Author

Let me know if there's anything else that this PR needs, more than happy to make necessary changes.

@josh

josh commented Feb 2, 2015

Copy link
Copy Markdown
Contributor

@MattKing17 looks good. I'll get to testing and merging today. Thanks so much! ❀️

josh added a commit that referenced this pull request Feb 2, 2015
Follow spec on Headers to throw TypeError, add tests for Headers
@josh
josh merged commit 261411d into JakeChampion:master Feb 2, 2015
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants