From 37657c79b66994147e41f31139ceb9c0c840868f Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Tue, 24 Oct 2023 13:26:03 -0700 Subject: [ruby/uri] Make URI#to_s prepend relative path with / if there is a host or port Otherwise, the path could be considered part of the host or port. This is better than modifying the path to make it absolute when a host or port is set. We could also raise for invalid paths when a host or port is set using check_path, but that results in weird errors, and won't catch issues (such as ftp allowing a relative path). Fixes [Bug #19916] https://github.com/ruby/uri/commit/ac32aa005b --- lib/uri/generic.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/uri/generic.rb') diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb index f3540a24bb..9ea2335cea 100644 --- a/lib/uri/generic.rb +++ b/lib/uri/generic.rb @@ -1364,6 +1364,9 @@ module URI str << ':' str << @port.to_s end + if (@host || @port) && !@path.empty? && !@path.start_with?('/') + str << '/' + end str << @path if @query str << '?' -- cgit v1.2.3