From 88bcccd4333fee37e90dc524ccb7cc20745e0332 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 20 May 2013 01:40:30 +0000 Subject: [PATCH] webrick: fix non-ascii escape bugs * lib/webrick/htmlutils.rb (WEBrick::HTMLUtils#escape): replace HTML meta chars even in non-ascii string. [Bug #8425] [ruby-core:55052] * lib/webrick/httputils.rb (WEBrick::HTTPUtils#{_escape,_unescape}): fix %-escape encodings. [Bug #8425] [ruby-core:55052] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40848 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 +++++++- lib/webrick/htmlutils.rb | 5 +++-- lib/webrick/httputils.rb | 14 ++++++++++++-- test/webrick/test_htmlutils.rb | 6 +++++- test/webrick/test_httputils.rb | 4 ++++ 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 49a8463756..31dc431223 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,10 @@ -Mon May 20 09:53:31 2013 Nobuyoshi Nakada +Mon May 20 10:40:21 2013 Nobuyoshi Nakada + + * lib/webrick/htmlutils.rb (WEBrick::HTMLUtils#escape): replace HTML + meta chars even in non-ascii string. [Bug #8425] [ruby-core:55052] + + * lib/webrick/httputils.rb (WEBrick::HTTPUtils#{_escape,_unescape}): + fix %-escape encodings. [Bug #8425] [ruby-core:55052] * lib/webrick/httpservlet/filehandler.rb (set_dir_list): revert r20152 partially and fix misuse of bytesize and regexp repetition operator. diff --git a/lib/webrick/htmlutils.rb b/lib/webrick/htmlutils.rb index ed901f1ce2..4cb3d0d7f6 100644 --- a/lib/webrick/htmlutils.rb +++ b/lib/webrick/htmlutils.rb @@ -15,12 +15,13 @@ module WEBrick # Escapes &, ", > and < in +string+ def escape(string) - str = string ? string.dup : "" + return "" unless string + str = string.b str.gsub!(/&/n, '&') str.gsub!(/\"/n, '"') str.gsub!(/>/n, '>') str.gsub!(/bar")) assert_equal("foo<bar", escape("foo