Skip to content
Browse files

Moved Domain regexp to a constant and added comments.

  • Loading branch information...
1 parent edbb78d commit 5609149d844ece5020dd53565d35cf69f563a8da @rizwanreza rizwanreza committed with josevalim
Showing with 8 additions and 1 deletion.
  1. +8 −1 actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
9 actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
@@ -93,6 +93,13 @@ def stale_session_check!
:cookie_only => true
+ # This regular expression is used to split the levels of a domain:
+ # So gives:
+ # $1 => www.
+ # $2 => example
+ # $3 =>
+ DOMAIN_REGEXP = /^(.*\.)*(.*)\.(...|...\...|....|..\...|..)$/
mat813 added a note

I'm wondering what it does in case the tld is longer than four characters, like, say, in
which should translate to

Or just .museum or .travel

What are the ideas to properly capture them? I can add |.....| etc... but that would be awful. I will have a look at more ways also.

For that reason i just only support second level domains in the first commit.

If you need something special, you must explicit declare the domain as a string:

:domain => :all # For 80% of cases second.level.
:domain => ""
:domain => "guillermoÁ"

2 .- The other implementation I though, maybe uglier, was:
:domain => :first_level # maybe for intranets or special domains: ".museum"
:domain => :second_level # normal cases: ""
:doamin => :all # alias for :second_level domain
:domain => :third_level # "" or ""
:domain => :fifth_level # ...
:domain => :sixth_level # ...

3.- # the last implementation i though was usign a proc:
:domain => :all
:domain => lambda {|env| rails.development? ? ".localhost" : "."+(env["HTTP_HOST"].split(".")[-4..-1].join(".")) }

As I did not come to any conclusions, i decided to just include :all for the 80% of the cases, and use a string for the others.

I can pass you any of this implementations tomorrow, if you want.

I think the current code does not satisfy the principle of minimum surprise, as you don't know what it will do in all circunstancies. Some times it will be second level and others third, and others, like .museum :domain will crash cookies as domain will be ".."

Obviously, i prefer my first implementation, maybe improving documentation and maybe w/ the second proposal (:first_level, :second_level, :third_level, ...) in this document .

After study, I considered not feasible to implement the existing mnemonics, and quite difficult to maintain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
def initialize(app, options = {})
@app = app
@default_options = DEFAULT_OPTIONS.merge(options)
@@ -123,7 +130,7 @@ def call(env)
if options[:domain] == :all
- env["HTTP_HOST"] =~ /^(.*\.)*(.*)\.(...|...\...|....|..\...)$/
options[:domain] = ".#{$2}.#{$3}"

0 comments on commit 5609149

Please sign in to comment.
Something went wrong with that request. Please try again.