aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_dispatch/http/url.rb26
-rw-r--r--guides/source/asset_pipeline.md2
2 files changed, 15 insertions, 13 deletions
diff --git a/actionpack/lib/action_dispatch/http/url.rb b/actionpack/lib/action_dispatch/http/url.rb
index 97cd32a308..75e426d3b0 100644
--- a/actionpack/lib/action_dispatch/http/url.rb
+++ b/actionpack/lib/action_dispatch/http/url.rb
@@ -5,18 +5,18 @@ module ActionDispatch
module Http
module URL
IP_HOST_REGEXP = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
- HOST_REGEXP = /(^.*:\/\/)?([^:]+)(?::(\d+$))?/
+ HOST_REGEXP = /(^[^:]+:\/\/)?([^:]+)(?::(\d+$))?/
PROTOCOL_REGEXP = /^([^:]+)(:)?(\/\/)?$/
mattr_accessor :tld_length
self.tld_length = 1
class << self
- def extract_domain(host, tld_length = @@tld_length)
+ def extract_domain(host, tld_length)
host.split('.').last(1 + tld_length).join('.') if named_host?(host)
end
- def extract_subdomains(host, tld_length = @@tld_length)
+ def extract_subdomains(host, tld_length)
if named_host?(host)
parts = host.split('.')
parts[0..-(tld_length + 2)]
@@ -25,7 +25,7 @@ module ActionDispatch
end
end
- def extract_subdomain(host, tld_length = @@tld_length)
+ def extract_subdomain(host, tld_length)
extract_subdomains(host, tld_length).join('.')
end
@@ -75,10 +75,11 @@ module ActionDispatch
def build_host_url(options)
protocol = options[:protocol]
host = options[:host]
+ port = options[:port]
if match = host.match(HOST_REGEXP)
protocol ||= match[1] unless protocol == false
host = match[2]
- options[:port] = match[3] unless options.key?(:port)
+ port = match[3] unless options.key? :port
end
protocol = normalize_protocol protocol
@@ -91,7 +92,7 @@ module ActionDispatch
end
result << host
- normalize_port(options[:port], protocol) { |port|
+ normalize_port(port, protocol) { |port|
result << ":#{port}"
}
@@ -99,7 +100,7 @@ module ActionDispatch
end
def named_host?(host)
- host && IP_HOST_REGEXP !~ host
+ IP_HOST_REGEXP !~ host
end
def normalize_protocol(protocol)
@@ -116,17 +117,18 @@ module ActionDispatch
end
def normalize_host(_host, options)
- return _host if !named_host?(_host)
+ return _host unless named_host?(_host)
tld_length = options[:tld_length] || @@tld_length
host = ""
- if options[:subdomain] == true || !options.key?(:subdomain)
+ subdomain = options[:subdomain]
+ if subdomain == true || !options.key?(:subdomain)
return _host if options[:domain].nil?
- host << extract_subdomain(_host, tld_length).to_param
- elsif options[:subdomain].present?
- host << options[:subdomain].to_param
+ host << extract_subdomain(_host, tld_length)
+ elsif subdomain
+ host << subdomain.to_param
end
host << "." unless host.empty?
host << (options[:domain] || extract_domain(_host, tld_length))
diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md
index 423b915873..2d1548f252 100644
--- a/guides/source/asset_pipeline.md
+++ b/guides/source/asset_pipeline.md
@@ -709,7 +709,7 @@ The default matcher for compiling files includes `application.js`,
automatically) from `app/assets` folders including your gems:
```ruby
-[ Proc.new { |path, fn| fn =~ /app\/assets/ && !%w(.js .css).include?(File.extname(path)) },
+[ Proc.new { |filename, path| path =~ /app\/assets/ && !%w(.js .css).include?(File.extname(filename)) },
/application.(css|js)$/ ]
```