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

Ensure some cookies don't cause failure #1645

Merged
merged 4 commits into from May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file. For info on
### Fixed

- Avoid NoMethodError when accessing Rack::Session::Cookie without requiring delegate first. ([#1610](https://github.com/rack/rack/issues/1610), [@onigra](https://github.com/onigra))
- Handle cookies with values that end in '=' ([#1645](https://github.com/rack/rack/pull/1645), [@lukaso](https://github.com/lukaso))

## [2.2.2] - 2020-02-11

Expand Down
4 changes: 2 additions & 2 deletions lib/rack/mock.rb
Expand Up @@ -254,9 +254,9 @@ def identify_cookie_attributes(cookie_filling)
cookie_bits = cookie_filling.split(';')
cookie_attributes = Hash.new
cookie_attributes.store('value', cookie_bits[0].strip)
cookie_bits.each do |bit|
cookie_bits.drop(1).each do |bit|
if bit.include? '='
cookie_attribute, attribute_value = bit.split('=')
cookie_attribute, attribute_value = bit.split('=',2)
cookie_attributes.store(cookie_attribute.strip, attribute_value.strip)
if cookie_attribute.include? 'max-age'
cookie_attributes.store('expires', Time.now + attribute_value.strip.to_i)
Expand Down
6 changes: 6 additions & 0 deletions test/spec_mock.rb
Expand Up @@ -319,6 +319,12 @@
secure_cookie.expires.must_be_nil
end

it "parses cookie headers with equals sign at the end" do
res = Rack::MockRequest.new(->(env) { [200, {"Set-Cookie" => "__cf_bm=_somebase64encodedstringwithequalsatthened=; array=awesome"}, [""]] }).get("")
cookie = res.cookie("__cf_bm")
cookie.value[0].must_equal "_somebase64encodedstringwithequalsatthened="
end

it "return nil if a non existent cookie is requested" do
res = Rack::MockRequest.new(app).get("")
res.cookie("i_dont_exist").must_be_nil
Expand Down