Skip to content

Commit

Permalink
updated escape_html not to escape forward slash
Browse files Browse the repository at this point in the history
fix: #2096
  • Loading branch information
JunichiIto authored and jeremyevans committed Jul 17, 2023
1 parent 3855d1d commit af9e278
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. For info on
### SPEC Changes

- `rack.input` is now optional. ([#1997](https://github.com/rack/rack/pull/1997), [@ioquatix])
- `Rack::Utils.escape_html` doesn't escape forward slash (`/`) now. ([#2097](https://github.com/rack/rack/pull/2097), [@JunichiIto])

### Changed

Expand Down
5 changes: 2 additions & 3 deletions lib/rack/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,14 @@ def best_q_match(q_value_header, available_mimes)
"<" => "&lt;",
">" => "&gt;",
"'" => "&#x27;",
'"' => "&quot;",
"/" => "&#x2F;"
'"' => "&quot;"
}

ESCAPE_HTML_PATTERN = Regexp.union(*ESCAPE_HTML.keys)

# Escape ampersands, brackets and quotes to their HTML/XML entities.
def escape_html(string)
string.to_s.gsub(ESCAPE_HTML_PATTERN){|c| ESCAPE_HTML[c] }
string.to_s.gsub(ESCAPE_HTML_PATTERN, ESCAPE_HTML)
end

def select_best_encoding(available_encodings, accept_encoding)
Expand Down
3 changes: 1 addition & 2 deletions test/spec_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,7 @@ def initialize(*)
Rack::Utils.escape_html("f>o").must_equal "f&gt;o"
Rack::Utils.escape_html("f'o").must_equal "f&#x27;o"
Rack::Utils.escape_html('f"o').must_equal "f&quot;o"
Rack::Utils.escape_html("f/o").must_equal "f&#x2F;o"
Rack::Utils.escape_html("<foo></foo>").must_equal "&lt;foo&gt;&lt;&#x2F;foo&gt;"
Rack::Utils.escape_html("<foo></foo>").must_equal "&lt;foo&gt;&lt;/foo&gt;"
end

it "escape html entities even on MRI when it's bugged" do
Expand Down

0 comments on commit af9e278

Please sign in to comment.