From 3566c6f02b2d1f3e84ff5cc565a8cbc676124a6b Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Wed, 18 Apr 2018 00:14:43 +0530 Subject: [PATCH] FIX: strip emoji string from slug --- lib/slug.rb | 2 ++ spec/components/slug_spec.rb | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/lib/slug.rb b/lib/slug.rb index dc95095b7b1..669006c2e8e 100644 --- a/lib/slug.rb +++ b/lib/slug.rb @@ -6,6 +6,8 @@ module Slug MAX_LENGTH = 255 def self.for(string, default = 'topic', max_length = MAX_LENGTH) + string = string.gsub(/:([\w\-+]+(?::t\d)?):/, '') if string.present? # strip emoji strings + slug = case (SiteSetting.slug_generation_method || :ascii).to_sym when :ascii then self.ascii_generator(string) diff --git a/spec/components/slug_spec.rb b/spec/components/slug_spec.rb index ad436f6b524..991ff235e14 100644 --- a/spec/components/slug_spec.rb +++ b/spec/components/slug_spec.rb @@ -24,6 +24,10 @@ describe Slug do expect(Slug.for("o_o_o")).to eq("o-o-o") end + it 'strips emoji string' do + expect(Slug.for(":smile: To Infinity and beyond! 🚀 :woman:t5:")).to eq("to-infinity-and-beyond") + end + context 'ascii generator' do before { SiteSetting.slug_generation_method = 'ascii' }