Skip to content

Commit

Permalink
The previous commit didn't work with complex domains, which is now fi…
Browse files Browse the repository at this point in the history
…xed.
  • Loading branch information
rizwanreza authored and josevalim committed Jun 11, 2010
1 parent 44830ea commit edbb78d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Expand Up @@ -121,12 +121,12 @@ def call(env)
unless options[:expire_after].nil?
cookie[:expires] = Time.now + options.delete(:expire_after)
end

if options[:domain] == :all
top_level_domain = env["HTTP_HOST"].split('.')[-2..-1].join('.')
options[:domain] = ".#{top_level_domain}"
env["HTTP_HOST"] =~ /^(.*\.)*(.*)\.(...|...\...|....|..\...)$/
options[:domain] = ".#{$2}.#{$3}"
end

request = ActionDispatch::Request.new(env)
set_cookie(request, cookie.merge!(options))
end
Expand Down
10 changes: 5 additions & 5 deletions actionpack/test/dispatch/session/cookie_store_test.rb
Expand Up @@ -39,7 +39,7 @@ def raise_data_overflow
session[:foo] = 'bye!' * 1024
head :ok
end

def rescue_action(e) raise end
end

Expand Down Expand Up @@ -192,28 +192,28 @@ def test_session_store_with_explicit_domain
headers['Set-Cookie']
end
end

def test_session_store_without_domain
with_test_route_set do
get '/set_session_value'
assert_no_match /domain\=/, headers['Set-Cookie']
end
end

def test_session_store_with_nil_domain
with_test_route_set(:domain => nil) do
get '/set_session_value'
assert_no_match /domain\=/, headers['Set-Cookie']
end
end

def test_session_store_with_all_domains
with_test_route_set(:domain => :all) do
get '/set_session_value'
assert_match /domain=\.example\.com/, headers['Set-Cookie']
end
end

private

# Overwrite get to send SessionSecret in env hash
Expand Down

0 comments on commit edbb78d

Please sign in to comment.