-
-
Notifications
You must be signed in to change notification settings - Fork 16
Properly strip whitespace from the right side of header values #48
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
base: main
Are you sure you want to change the base?
Conversation
|
This looks good to me, but I want to draw your attention to https://github.com/socketry/protocol-http1/blob/main/test/protocol/http1/parser.rb which is testing these patterns to ensure they match in linear time. |
Interesting :) Assuming the test works, I'm not sure why it's passing. Worst-case on this regex should be |
|
Okay, clearly I don't understand regexes as well as I thought I did :)
|
|
Modern Ruby implementations use memoization to avoid exponential backtracking (trading memory for computation), so it can depend on the implementation, which is why |
I ended up going down that rabbithole last night and reading the paper referenced in the Ruby docs. Pretty cool!
As it is, the current pattern clearly needs to change, given that the final OWS is useless (the preceding Anyway, the only pattern I can think of that doesn't use non-greedy matching would be something like this (imo, gross): FIELD_VALUE = /|[^ \t\0\r\n]|[^ \t\0\r\n][^\0\r\n]*[^ \t\0\r\n]/.freezeThat is, 3 cases:
Would this be preferable? |
|
TBH, as long as |
|
We want to strip only spaces and tabs, but |
Fixes #47.
Contribution