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

Fix HTTP::Cookie parse quoted cookie value #10853

Conversation

straight-shoota
Copy link
Member

HTTP::Cookies::Parser correctly recognizes a quoted cookie value, but it doesn't dequote when creating the HTTP::Cookie instance. This leads to a validation error (#10485).

Reported in https://forum.crystal-lang.org/t/invalid-cookie-value-error-in-kemal-how-to-fix/3427

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:networking labels Jun 26, 2021
@@ -152,7 +152,12 @@ module HTTP

def parse_cookies(header)
header.scan(CookieString).each do |pair|
yield Cookie.new(pair["name"], pair["value"])
value = pair["value"]
if value.starts_with?('"')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be check end_with also?

Copy link
Member Author

@straight-shoota straight-shoota Jun 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not necessary because the regex makes sure there are delimiters on both ends.

Copy link
Member

@sdogruyol sdogruyol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @straight-shoota 🙏

@straight-shoota straight-shoota added this to the 1.1.0 milestone Jun 28, 2021
@straight-shoota straight-shoota merged commit ad943e9 into crystal-lang:master Jun 29, 2021
@straight-shoota straight-shoota deleted the fix/http-cookie-quoted_value branch June 29, 2021 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:networking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants