Skip to content

A platform for community discussion. Free, open, simple.

FIX: unicode titles missing when visiting topic from topic list

Sam081959227de7
diff --git a/app/assets/javascripts/discourse/routes/topic.js.es6 b/app/assets/javascripts/discourse/routes/topic.js.es6
index 50867225346..83205ff599c 100644
--- a/app/assets/javascripts/discourse/routes/topic.js.es6
+++ b/app/assets/javascripts/discourse/routes/topic.js.es6
@@ -20,7 +20,7 @@ const TopicRoute = Discourse.Route.extend({
titleToken() {
const model = this.modelFor('topic');
if (model) {
- const result = model.get('unicode_title') ? model.get('unicode_title') : model.get('title'),
+ const result = model.get('unicode_title') || model.get('title'),
cat = model.get('category');
// Only display uncategorized in the title tag if it was renamed
diff --git a/app/serializers/listable_topic_serializer.rb b/app/serializers/listable_topic_serializer.rb
index 13a87235c10..aeecddbeaef 100644
--- a/app/serializers/listable_topic_serializer.rb
+++ b/app/serializers/listable_topic_serializer.rb
@@ -22,10 +22,19 @@ class ListableTopicSerializer < BasicTopicSerializer
:is_warning,
:notification_level,
:bookmarked,
- :liked
+ :liked,
+ :unicode_title
has_one :last_poster, serializer: BasicUserSerializer, embed: :objects
+ def include_unicode_title?
+ object.title.match?(/:[\w\-+]+:/)
+ end
+
+ def unicode_title
+ Emoji.gsub_emoji_to_unicode(object.title)
+ end
+
def highest_post_number
(scope.is_staff? && object.highest_staff_post_number) || object.highest_post_number
end
diff --git a/app/serializers/topic_view_serializer.rb b/app/serializers/topic_view_serializer.rb
index 9f6ea937e8b..9297793726d 100644
--- a/app/serializers/topic_view_serializer.rb
+++ b/app/serializers/topic_view_serializer.rb
@@ -267,7 +267,7 @@ class TopicViewSerializer < ApplicationSerializer
end
def include_unicode_title?
- !!(object.topic.title =~ /:([\w\-+]*):/)
+ object.topic.title.match?(/:[\w\-+]+:/)
end
def unicode_title
diff --git a/lib/freedom_patches/match.rb b/lib/freedom_patches/match.rb
new file mode 100644
index 00000000000..56084edaf6a
--- /dev/null
+++ b/lib/freedom_patches/match.rb
@@ -0,0 +1,8 @@
+class String
+ # new to Ruby 2.4, fastest way of matching a string to a regex
+ unless method_defined? :match?
+ def match?(regex)
+ !!(self =~ regex)
+ end
+ end
+end
diff --git a/lib/freedom_patches/scrub.rb b/lib/freedom_patches/scrub.rb
deleted file mode 100644
index 05c1dba04d4..00000000000
--- a/lib/freedom_patches/scrub.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-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(replace_char = nil)
- 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