lib/rack/utils.rb in rack-3.1.2 vs lib/rack/utils.rb in rack-3.1.3

- old
+ new

@@ -4,11 +4,11 @@ require 'uri' require 'fileutils' require 'set' require 'tempfile' require 'time' -require 'cgi/escape' +require 'erb' require_relative 'query_parser' require_relative 'mime' require_relative 'headers' require_relative 'constants' @@ -174,12 +174,21 @@ (match.split('/', 2).count('*') * -10) + quality end.last matches&.first end - # Escape ampersands, brackets and quotes to their HTML/XML entities. - define_method(:escape_html, CGI.method(:escapeHTML)) + # Introduced in ERB 4.0. ERB::Escape is an alias for ERB::Utils which + # doesn't get monkey-patched by rails + if defined?(ERB::Escape) && ERB::Escape.instance_method(:html_escape) + define_method(:escape_html, ERB::Escape.instance_method(:html_escape)) + else + require 'cgi/escape' + # Escape ampersands, brackets and quotes to their HTML/XML entities. + def escape_html(string) + CGI.escapeHTML(string.to_s) + end + end def select_best_encoding(available_encodings, accept_encoding) # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html expanded_accept_encoding = [] @@ -580,12 +589,14 @@ if status.is_a?(Symbol) SYMBOL_TO_STATUS_CODE.fetch(status) do fallback_code = OBSOLETE_SYMBOLS_TO_STATUS_CODES.fetch(status) { raise ArgumentError, "Unrecognized status code #{status.inspect}" } message = "Status code #{status.inspect} is deprecated and will be removed in a future version of Rack." if canonical_symbol = OBSOLETE_SYMBOL_MAPPINGS[status] - message = "#{message} Please use #{canonical_symbol.inspect} instead." + # message = "#{message} Please use #{canonical_symbol.inspect} instead." + # For now, let's not emit any warning when there is a mapping. + else + warn message, uplevel: 3 end - warn message, uplevel: 1 fallback_code end else status.to_i end