diff options
author | Bryce Thornton <brycethornton@gmail.com> | 2010-08-14 15:35:01 -0400 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-08-15 16:42:02 -0300 |
commit | fd78bb727045547371179428886c9b262d66091d (patch) | |
tree | cf7e194c3d12397429f74e67a2b3154b5d1563dc /actionpack/lib/action_dispatch/middleware | |
parent | ada8c66ba06777177f9313198f404fdd1458d24d (diff) | |
download | rails-fd78bb727045547371179428886c9b262d66091d.tar.gz rails-fd78bb727045547371179428886c9b262d66091d.tar.bz2 rails-fd78bb727045547371179428886c9b262d66091d.zip |
Allow for any possible TLD when using the :all option with the cookie session store. This works for subdomain.mysite.local, google.co.uk, google.com.au, etc. [#5147 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/cookies.rb | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb index 4d33cd3b0c..c281e323e5 100644 --- a/actionpack/lib/action_dispatch/middleware/cookies.rb +++ b/actionpack/lib/action_dispatch/middleware/cookies.rb @@ -69,16 +69,26 @@ module ActionDispatch class CookieJar < Hash #:nodoc: - # This regular expression is used to split the levels of a domain - # So www.example.co.uk gives: - # $1 => www. - # $2 => example - # $3 => co.uk - DOMAIN_REGEXP = /^(.*\.)*(.*)\.(...|...\...|....|..\...|..)$/ + # This regular expression is used to split the levels of a domain. + # The top level domain can be any string without a period or + # **.**, ***.** style TLDs like co.uk or com.au + # + # www.example.co.uk gives: + # $1 => example + # $2 => co.uk + # + # example.com gives: + # $1 => example + # $2 => com + # + # lots.of.subdomains.example.local gives: + # $1 => example + # $2 => local + DOMAIN_REGEXP = /([^.]*)\.([^.]*|..\...|...\...)$/ def self.build(request) secret = request.env[TOKEN_KEY] - host = request.env["HTTP_HOST"] + host = request.host new(secret, host).tap do |hash| hash.update(request.cookies) @@ -104,7 +114,7 @@ module ActionDispatch if options[:domain] == :all @host =~ DOMAIN_REGEXP - options[:domain] = ".#{$2}.#{$3}" + options[:domain] = ".#{$1}.#{$2}" end end |