FEATURE: backport a minimal String#scrub
BUGFIX: invalid byte sequence in email would explode all processing
This commit is contained in:
parent
81eec5ff06
commit
9738c4ff48
|
@ -25,14 +25,7 @@ module ApplicationHelper
|
||||||
|
|
||||||
def escape_unicode(javascript)
|
def escape_unicode(javascript)
|
||||||
if javascript
|
if javascript
|
||||||
javascript = javascript.dup.force_encoding("utf-8")
|
javascript = javascript.scrub
|
||||||
|
|
||||||
unless javascript.valid_encoding?
|
|
||||||
# work around bust string with a double conversion
|
|
||||||
javascript.encode!("utf-16","utf-8",:invalid => :replace)
|
|
||||||
javascript.encode!("utf-8","utf-16")
|
|
||||||
end
|
|
||||||
|
|
||||||
javascript.gsub!(/\342\200\250/u, '
')
|
javascript.gsub!(/\342\200\250/u, '
')
|
||||||
javascript.gsub!(/(<\/)/u, '\u003C/')
|
javascript.gsub!(/(<\/)/u, '\u003C/')
|
||||||
javascript.html_safe
|
javascript.html_safe
|
||||||
|
|
|
@ -94,10 +94,10 @@ module Email
|
||||||
end
|
end
|
||||||
|
|
||||||
def discourse_email_parser
|
def discourse_email_parser
|
||||||
lines = @body.lines.to_a
|
lines = @body.scrub.lines.to_a
|
||||||
range_end = 0
|
range_end = 0
|
||||||
|
|
||||||
email_year = lines.each_with_index do |l, idx|
|
lines.each_with_index do |l, idx|
|
||||||
break if l =~ /\A\s*\-{3,80}\s*\z/ ||
|
break if l =~ /\A\s*\-{3,80}\s*\z/ ||
|
||||||
l =~ Regexp.new("\\A\\s*" + I18n.t('user_notifications.previous_discussion') + "\\s*\\Z") ||
|
l =~ Regexp.new("\\A\\s*" + I18n.t('user_notifications.previous_discussion') + "\\s*\\Z") ||
|
||||||
(l =~ /via #{SiteSetting.title}(.*)\:$/) ||
|
(l =~ /via #{SiteSetting.title}(.*)\:$/) ||
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
class String
|
||||||
|
# A poor man's scrub, Ruby 2.1 has a much better implementation, but this will do
|
||||||
|
unless method_defined? :scrub
|
||||||
|
def scrub
|
||||||
|
str = dup.force_encoding("utf-8")
|
||||||
|
|
||||||
|
unless str.valid_encoding?
|
||||||
|
# work around bust string with a double conversion
|
||||||
|
str.encode!("utf-16","utf-8",:invalid => :replace)
|
||||||
|
str.encode!("utf-8","utf-16")
|
||||||
|
end
|
||||||
|
|
||||||
|
str
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue