2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00

FIX: always truncate uncomplete emojis in excerpts (#11678)

Additional fix after https://github.com/discourse/discourse/pull/11667

Always truncate "broken" emojis from excerpts.
This commit is contained in:
Krzysztof Kotlarek 2021-01-11 13:43:11 +11:00 committed by GitHub
parent 7f78b6ec10
commit efaa63bd1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 18 deletions

View file

@ -13,7 +13,6 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
options || {}
@strip_links = options[:strip_links] == true
@strip_images = options[:strip_images] == true
@strip_truncated_emoji_code = options[:strip_truncated_emoji_code] == true
@text_entities = options[:text_entities] == true
@markdown_images = options[:markdown_images] == true
@keep_newlines = options[:keep_newlines] == true
@ -208,7 +207,7 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
encode = encode ? lambda { |s| ERB::Util.html_escape(s) } : lambda { |s| s }
if count_it && @current_length + string.length > @length
length = [0, @length - @current_length - 1].max
@excerpt << encode.call(string[0..length]) if truncate && !truncated_emoji_code?(string)
@excerpt << encode.call(string[0..length]) if truncate && !emoji?(string)
@excerpt << (@text_entities ? "..." : "&hellip;")
@excerpt << "</a>" if @in_a
@excerpt << after_string if after_string
@ -220,11 +219,7 @@ class ExcerptParser < Nokogiri::XML::SAX::Document
@current_length += string.length if count_it
end
def truncated_emoji_code?(string)
@strip_truncated_emoji_code && emoji?(string)
end
def emoji?(string)
string.match?(/:\w+:/)
string.match?(/\A:\w+:\Z/)
end
end