Skip to content

Commit

Permalink
Merge pull request #1645 from simplybusiness/base64_cookie_values
Browse files Browse the repository at this point in the history
Ensure some cookies don't cause failure
  • Loading branch information
tenderlove committed May 22, 2020
2 parents 4d170b7 + c17569c commit 6a50e46
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
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

0 comments on commit 6a50e46

Please sign in to comment.