Skip to content
This repository was archived by the owner on Dec 2, 2018. It is now read-only.

Commit 1f50aa0

Browse files
committed
more robust handling of encoding issues
1 parent 317f694 commit 1f50aa0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/rack/legacy/error_page.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ def h(s)
9797
# Use HTML entities for non-ASCII characters
9898
unpack("U*").collect { |s| s > 127 ? "&##{s};" : s.chr }.join("")
9999
rescue ArgumentError => e
100-
case e.message
101-
when "invalid byte sequence in US-ASCII" then
102-
# Assume UTF-8 string
103-
s.force_encoding('UTF-8') and retry
100+
if e.message =~ /invalid byte sequence/
101+
# Get rid of incorrectly encoded characters
102+
s = s.chars.collect { |c| c.valid_encoding? ? c : '?' }.join
103+
retry
104104
end
105105
raise e
106106
end

0 commit comments

Comments
 (0)