Properly strip whitespace from the right side of header values#48
Properly strip whitespace from the right side of header values#48kenballus wants to merge 1 commit intosocketry:mainfrom
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