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

regular expression applied over the http header value #1511

Open
yuqinlear opened this issue Jun 2, 2016 · 3 comments
Open

regular expression applied over the http header value #1511

yuqinlear opened this issue Jun 2, 2016 · 3 comments

Comments

@yuqinlear
Copy link

I have some Http header value fails during the validation. I think the regexp works improper.
jsdom\lib\jsdom\living\helpers\headers.js line 11.

exports.fieldValueRegexp = /^[ \t]*(?:[\x21-\x7E\x80-\xFF](?:[ \t][\x21-\x7E\x80-\xFF])?)*[ \t]*$/;

test case:

fieldValueRegexp.test('a b'); //true
fieldValueRegexp.test('a b c'); //false
fieldValueRegexp.test('aa bb cc dd'); //true
fieldValueRegexp.test('this is a test'); //false
@domenic
Copy link
Member

domenic commented Jun 2, 2016

I don't understand the bug. What is the behavior you are seeing in jsdom that is different from browsers?

@yuqinlear
Copy link
Author

Hi, @domenic
I have a header as X-our-own-header: the value is a fixed phrase.
The request fails as "the value is a fixed phrase." is invalid at jsdom, which behaves differently from my browser (chrome).
fieldValueRegexp.test('the value is a fixed phrase.') // false
Thank you!

@nicolashenry
Copy link
Contributor

https://tools.ietf.org/html/rfc7230#section-3.2

     header-field   = field-name ":" OWS field-value OWS
     field-name     = token
     field-value    = *( field-content / obs-fold )
     field-content  = field-vchar [ 1*( SP / HTAB ) field-vchar ]
     field-vchar    = VCHAR / obs-text

     obs-fold       = CRLF 1*( SP / HTAB )
                    ; obsolete line folding
                    ; see Section 3.2.4

Maybe it should be /^[ \t]*(?:[\x20-\x7E\x80-\xFF](?:[ \t]+[\x20-\x7E\x80-\xFF])?)*[ \t]*$/ because '\x20' could be a "visible [USASCII] character" but I am not sure. Also note that 1*( SP / HTAB ) should give [ \t]+ and not [ \t].

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

3 participants