Skip to content

Commit

Permalink
Ignore leading dot when merging cookies
Browse files Browse the repository at this point in the history
Most recent specification states that leading dots are ignored by user
agents: https://httpwg.org/specs/rfc6265.html#sane-domain
  • Loading branch information
stevecrozz committed Feb 2, 2023
1 parent 73c7174 commit 70f4db2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rack/test/cookie_jar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ def initialize(raw, uri = nil, default_host = DEFAULT_HOST)
@name, @value = parse_query(@raw, ';').to_a.first
@options = parse_query(options, ';')

if @options['domain']
if domain = @options['domain']
@exact_domain_match = false
domain[0] = '' if domain[0] == '.'
else
# If the domain attribute is not present in the cookie,
# the domain must match exactly.
Expand Down
6 changes: 6 additions & 0 deletions spec/rack/test/cookie_jar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
jar_clone.to_hash.must_be_empty
end

it 'ignores leading dot in domain' do
jar = Rack::Test::CookieJar.new
jar << Rack::Test::Cookie.new('a=c; domain=.lithostech.com', URI('https://lithostech.com'))
jar.get_cookie('a').domain.must_equal 'lithostech.com'
end

it '#[] and []= should get and set cookie values' do
jar = Rack::Test::CookieJar.new
jar[cookie_name].must_be_nil
Expand Down

0 comments on commit 70f4db2

Please sign in to comment.