mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Always use the provided port for protocol relative urls
There may be situations where you need to tunnel SSL connections over port 80 so we shouldn't remove it if it has been explicitly provided.
This commit is contained in:
parent
be93d94ef2
commit
2378f69e69
3 changed files with 20 additions and 0 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
* Always use the provided port if the protocol is relative.
|
||||||
|
|
||||||
|
Fixes #15043.
|
||||||
|
|
||||||
|
*Guilherme Cavalcanti*, *Andrew White*
|
||||||
|
|
||||||
* Moved `params[request_forgery_protection_token]` into its own method
|
* Moved `params[request_forgery_protection_token]` into its own method
|
||||||
and improved tests.
|
and improved tests.
|
||||||
|
|
||||||
|
|
|
@ -135,6 +135,8 @@ module ActionDispatch
|
||||||
return nil if options[:port].nil? || options[:port] == false
|
return nil if options[:port].nil? || options[:port] == false
|
||||||
|
|
||||||
case options[:protocol]
|
case options[:protocol]
|
||||||
|
when "//"
|
||||||
|
options[:port]
|
||||||
when "https://"
|
when "https://"
|
||||||
options[:port].to_i == 443 ? nil : options[:port]
|
options[:port].to_i == 443 ? nil : options[:port]
|
||||||
else
|
else
|
||||||
|
|
|
@ -64,18 +64,30 @@ module TestUrlGeneration
|
||||||
|
|
||||||
test "port is extracted from the host" do
|
test "port is extracted from the host" do
|
||||||
assert_equal "http://www.example.com:8080/foo", foo_url(host: "www.example.com:8080", protocol: "http://")
|
assert_equal "http://www.example.com:8080/foo", foo_url(host: "www.example.com:8080", protocol: "http://")
|
||||||
|
assert_equal "//www.example.com:8080/foo", foo_url(host: "www.example.com:8080", protocol: "//")
|
||||||
|
assert_equal "//www.example.com:80/foo", foo_url(host: "www.example.com:80", protocol: "//")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "port option is used" do
|
||||||
|
assert_equal "http://www.example.com:8080/foo", foo_url(host: "www.example.com", protocol: "http://", port: 8080)
|
||||||
|
assert_equal "//www.example.com:8080/foo", foo_url(host: "www.example.com", protocol: "//", port: 8080)
|
||||||
|
assert_equal "//www.example.com:80/foo", foo_url(host: "www.example.com", protocol: "//", port: 80)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "port option overrides the host" do
|
test "port option overrides the host" do
|
||||||
assert_equal "http://www.example.com:8080/foo", foo_url(host: "www.example.com:8443", protocol: "http://", port: 8080)
|
assert_equal "http://www.example.com:8080/foo", foo_url(host: "www.example.com:8443", protocol: "http://", port: 8080)
|
||||||
|
assert_equal "//www.example.com:8080/foo", foo_url(host: "www.example.com:8443", protocol: "//", port: 8080)
|
||||||
|
assert_equal "//www.example.com:80/foo", foo_url(host: "www.example.com:443", protocol: "//", port: 80)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "port option disables the host when set to nil" do
|
test "port option disables the host when set to nil" do
|
||||||
assert_equal "http://www.example.com/foo", foo_url(host: "www.example.com:8443", protocol: "http://", port: nil)
|
assert_equal "http://www.example.com/foo", foo_url(host: "www.example.com:8443", protocol: "http://", port: nil)
|
||||||
|
assert_equal "//www.example.com/foo", foo_url(host: "www.example.com:8443", protocol: "//", port: nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "port option disables the host when set to false" do
|
test "port option disables the host when set to false" do
|
||||||
assert_equal "http://www.example.com/foo", foo_url(host: "www.example.com:8443", protocol: "http://", port: false)
|
assert_equal "http://www.example.com/foo", foo_url(host: "www.example.com:8443", protocol: "http://", port: false)
|
||||||
|
assert_equal "//www.example.com/foo", foo_url(host: "www.example.com:8443", protocol: "//", port: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "keep subdomain when key is true" do
|
test "keep subdomain when key is true" do
|
||||||
|
|
Loading…
Reference in a new issue