Repository: rails/rails
File: actionpack/lib/action_dispatch/http/url.rb (Ruby)

Code before:
            query = params.to_query
            path << "?#{query}" unless query.empty?
          end

          def add_anchor(path, anchor)
            if anchor
              path << "##{Journey::Router::Utils.escape_fragment(anchor.to_param)}"
            end
          end

          def extract_domain_from(host, tld_length)
            domain_extractor.domain_from(host, tld_length)
          end

          def extract_subdomains_from(host, tld_length)
            domain_extractor.subdomains_from(host, tld_length)
          end

          def build_host_url(host, port, protocol, options, path)
            if match = host.match(HOST_REGEXP)
              protocol_from_host = match[1] if protocol.nil?
              host               = match[2]
              port               = match[3] unless options.key? :port
            end

            protocol = protocol_from_host || normalize_protocol(protocol)
            host     = normalize_host(host, options)

            result = protocol_from_host ? protocol : protocol.dup

            if options[:user] && options[:password]
              result << "#{Rack::Utils.escape(options[:user])}:#{Rack::Utils.escape(options[:password])}@"
            end

            result << host
            normalize_port(port, protocol) { |normalized_port|
              result << ":#{normalized_port}"
            }

            result.concat path
          end

          def named_host?(host)
            !IP_HOST_REGEXP.match?(host)
          end

          def normalize_protocol(protocol)
            case protocol
            when nil
              secure_protocol ? "https://" : "http://"
            when false, "//"

Review comment (suggestion):
Previously this would always normalize `protocol`.
Does this skip normalizing `protocol_from_host` now when the regexp matches?

**Edit** Nevermind, that's the purpose of this whole PR 🙃 

Code after:
            query = params.to_query
            path << "?#{query}" unless query.empty?
          end

          def add_anchor(path, anchor)
            if anchor
              path << "##{Journey::Router::Utils.escape_fragment(anchor.to_param)}"
            end
          end

          def extract_domain_from(host, tld_length)
            domain_extractor.domain_from(host, tld_length)
          end

          def extract_subdomains_from(host, tld_length)
            domain_extractor.subdomains_from(host, tld_length)
          end

          def build_host_url(host, port, protocol, options, path)
            if match = host.match(HOST_REGEXP)
              protocol_from_host = match[1] if protocol.nil?
              host               = match[2]
              port               = match[3] unless options.key? :port
            end

            protocol = protocol_from_host || normalize_protocol(protocol).dup
            host     = normalize_host(host, options)
            port     = normalize_port(port, protocol)

            result = protocol

            if options[:user] && options[:password]
              result << "#{Rack::Utils.escape(options[:user])}:#{Rack::Utils.escape(options[:password])}@"
            end

            result << host

            result << ":" << port.to_s if port

            result.concat path
          end

          def named_host?(host)
            !IP_HOST_REGEXP.match?(host)
          end

          def normalize_protocol(protocol)
            case protocol
            when nil
              secure_protocol ? "https://" : "http://"
            when false, "//"