diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb index 0c4ceb5c39..b03244d025 100644 --- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb @@ -93,6 +93,13 @@ module ActionDispatch :cookie_only => true } + # 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 = /^(.*\.)*(.*)\.(...|...\...|....|..\...|..)$/ + def initialize(app, options = {}) @app = app @default_options = DEFAULT_OPTIONS.merge(options) @@ -123,7 +130,7 @@ module ActionDispatch end if options[:domain] == :all - env["HTTP_HOST"] =~ /^(.*\.)*(.*)\.(...|...\...|....|..\...)$/ + env["HTTP_HOST"] =~ DOMAIN_REGEXP options[:domain] = ".#{$2}.#{$3}" end