Issue #13307 has been updated by Martin Drst.


I agree with Shyouhei that the current behavior is inconsistent. When changing the scheme, either the object keeps the default port (which is 443 for https), or it keeps port 80. If it keeps port 80, then it has to print that out when the scheme is https, because port 80 isn't the default for https.

BTW, the examples should all have '//' after http(s):, but that doesn't affect the result.


----------------------------------------
Bug #13307: Changing scheme from http to https for the URI does not change the port number
https://bugs.ruby-lang.org/issues/13307#change-63527

* Author: Martin Chabot
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
If we change the scheme of an URI, it does not change the port number. The URI object become inconsistent. If we print the full URI it does not return the same port number as when we print the port.

See code bellow:

~~~
[1] pry(main)> require 'uri'
=> true
[2] pry(main)> url = "http:devalphaserver.com/xxx/12"
=> "http:devalphaserver.com/xxx/12"
[3] pry(main)> uri = URI.parse(url)
=> #<URI::HTTP http:devalphaserver.com/xxx/12>
[4] pry(main)> uri.scheme = "https"
=> "https"
[5] pry(main)> uri.port
=> 80
[6] pry(main)> uri.to_s
=> "https:devalphaserver.com/xxx/12" # port 443
~~~








-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>