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
Parse cookie pairs without a regex #81
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few quick comments.
I like that this logic allows value pairs inside a double-quoted string to be found, like
a="b; c=d; e="
. Yours will find a="b
, c=d
, e="
, while the regex just finds a=b; c=d; e=
.
Did you verify that it is actually faster?
Thanks for the review @kanongil. I agree with all your notes re: I did confirm it was faster, too! Here's a quick peek at the time for 100 random runs (x is a run with a given random cookie string, y is time). Expand graph:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loose parsing is probably for the best.
The main behavioural change is the mentioned exposing of new value-pairs with mis-matched '"', which I would consider a bug fix. Maybe you can add a test for when they match as well? Eg. for a="; b=2; "; c=3
. Here the regex returns a=; b=2;
& c=3
, while your logic would return something like a="
, b=2
& "; c=3
.
Sounds good, I will take a look at that and at minimum add a test 👍 |
Using a simple parser rather than a regex is a more direct, durable, and performant solution to collecting cookie name-value pairs. I think that writing this logic out also makes it a bit clearer how we treat bad/invalid cookies. In order to confirm that the behavior remains identical to the regex-based parser, I added tests for a couple additional edge-cases.