Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should support both SPACE and HTAB as whitespace #13

Closed
rg2011 opened this issue Jan 28, 2024 · 3 comments
Closed

Should support both SPACE and HTAB as whitespace #13

rg2011 opened this issue Jan 28, 2024 · 3 comments

Comments

@rg2011
Copy link

rg2011 commented Jan 28, 2024

Currently, the parse function can parse media types surrounded by whitespaces, but not tabs:

$ node
Welcome to Node.js v20.10.0.
Type ".help" for more information.
> var typer = require('media-typer')
undefined
> typer.parse("text/html ")
MediaType { type: 'text', subtype: 'html', suffix: undefined }
> typer.parse("text/html\t")
Uncaught TypeError: invalid media type
    at Object.parse (/mnt/wsl/tank/projects/type-is/node_modules/media-typer/index.js:117:11)
> 

However, I believe HTAB should be a valid whitespace character in the context of Content-Type header parsing. The specification for the Content-Type header (https://www.rfc-editor.org/rfc/rfc9110#field.content-type) states that:

The type/subtype MAY be followed by semicolon-delimited parameters (Section 5.6.6) in the form of name/value pairs.

And section 5.6.6 defines the semicolon-delimited parameters as:

  parameters      = *( OWS ";" OWS [ parameter ] )
  parameter       = parameter-name "=" parameter-value
  parameter-name  = token
  parameter-value = ( token / quoted-string )

Where OWS is defined in section 5.6.3 as:

  OWS            = *( SP / HTAB )
                 ; optional whitespace

So the media-type might be followed by HTABs in a valid Content-Type header. If the parser function supports trailing spaces, it should as well support trailing tabs.

rg2011 added a commit to rg2011/media-typer that referenced this issue Jan 28, 2024
@rg2011 rg2011 mentioned this issue Jan 28, 2024
@dougwilson
Copy link
Contributor

Hello, and thank you for your issue. This module is not made to follow the parsing rules of the HTTP content-typr header, just the RFC that is outlined in the readme.

@dougwilson
Copy link
Contributor

I will look to see if RFC 6838 allows tabs or not as well, though I gotta run some errands, but if you find so I can definitely reopen or I will if I find it does.

@rg2011
Copy link
Author

rg2011 commented Feb 5, 2024

Hi,

Thanks for reviewing the issue, and sorry for not replying before. I checked the issue on the phone and it seemed I couldn't reply to a closed one. But from desktop I can :D

I understand the motivation to close the issue, and I will not reopen it. I am only commenting to bring your attention to jshttp/type-is#52. I moved the issue there because type-is does deal with the Content-Type header, so it looks like the proper place to fix it..

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

No branches or pull requests

2 participants