diff options
Diffstat (limited to 'lib/webrick/httputils.rb')
-rw-r--r-- | lib/webrick/httputils.rb | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/webrick/httputils.rb b/lib/webrick/httputils.rb index a0ca3a48c7..a5f0632b86 100644 --- a/lib/webrick/httputils.rb +++ b/lib/webrick/httputils.rb @@ -437,8 +437,18 @@ module WEBrick def _make_regex(str) /([#{Regexp.escape(str)}])/n end def _make_regex!(str) /([^#{Regexp.escape(str)}])/n end - def _escape(str, regex) str.gsub(regex){ "%%%02X" % $1.ord } end - def _unescape(str, regex) str.gsub(regex){ $1.hex.chr } end + def _escape(str, regex) + str = str.b + str.gsub!(regex) {"%%%02X" % $1.ord} + # %-escaped string should contain US-ASCII only + str.force_encoding(Encoding::US_ASCII) + end + def _unescape(str, regex) + str = str.b + str.gsub!(regex) {$1.hex.chr} + # encoding of %-unescaped string is unknown + str + end UNESCAPED = _make_regex(control+space+delims+unwise+nonascii) UNESCAPED_FORM = _make_regex(reserved+control+delims+unwise+nonascii) |