Permalink
Browse files

push only_path conditional up

  • Loading branch information...
1 parent 960398c commit 5f49da8c6de50e0b8ab143faa1043a21239f70ec @tenderlove tenderlove committed May 20, 2014
Showing with 19 additions and 18 deletions.
  1. +19 −18 actionpack/lib/action_dispatch/http/url.rb
@@ -37,7 +37,11 @@ def url_for(options)
path = options[:script_name].to_s.chomp("/")
path << options[:path].to_s
- result = build_host_url(options)
+ if options[:only_path]
+ result = ''
+ else
+ result = build_host_url(options)
+ end
if options[:trailing_slash]
if path.include?('?')
@@ -65,28 +69,25 @@ def url_for(options)
private
def build_host_url(options)
- result = ""
+ if match = options[:host].match(HOST_REGEXP)
+ options[:protocol] ||= match[1] unless options[:protocol] == false
+ options[:host] = match[2]
+ options[:port] = match[3] unless options.key?(:port)
+ end
- unless options[:only_path]
- if match = options[:host].match(HOST_REGEXP)
- options[:protocol] ||= match[1] unless options[:protocol] == false
- options[:host] = match[2]
- options[:port] = match[3] unless options.key?(:port)
- end
+ options[:protocol] = normalize_protocol(options)
+ options[:host] = normalize_host(options)
+ options[:port] = normalize_port(options)
- options[:protocol] = normalize_protocol(options)
- options[:host] = normalize_host(options)
- options[:port] = normalize_port(options)
+ result = options[:protocol]
- result << options[:protocol]
+ if options[:user] && options[:password]
+ result << "#{Rack::Utils.escape(options[:user])}:#{Rack::Utils.escape(options[:password])}@"
+ end
- if options[:user] && options[:password]
- result << "#{Rack::Utils.escape(options[:user])}:#{Rack::Utils.escape(options[:password])}@"
- end
+ result << options[:host]
+ result << ":#{options[:port]}" if options[:port]
- result << options[:host]
- result << ":#{options[:port]}" if options[:port]
- end
result
end

0 comments on commit 5f49da8

Please sign in to comment.