Fix replacing of  , aka   so it works on 1.9

This commit is contained in:
Michael Fellinger 2009-06-07 17:03:13 +09:00
parent 520081c93e
commit 8d2c027089
1 changed files with 7 additions and 3 deletions

View File

@ -45,10 +45,14 @@ module Webrat
end
def replace_nbsp(str)
if str.respond_to?(:force_encoding)
str.force_encoding('UTF-8').gsub(/\xc2\xa0/u, ' ')
if str.respond_to?(:valid_encoding?)
if str.valid_encoding?
str.gsub(/\xc2\xa0/u, ' ')
else
str.force_encoding('UTF-8').gsub(/\xc2\xa0/u, ' ')
end
else
str.gsub("\xc2\xa0", ' ')
str.gsub(/\xc2\xa0/u, ' ')
end
end