diff --git a/lib/text_cleaner.rb b/lib/text_cleaner.rb index 31ff605cef3..0914fe88881 100644 --- a/lib/text_cleaner.rb +++ b/lib/text_cleaner.rb @@ -17,7 +17,8 @@ class TextCleaner remove_all_periods_from_the_end: SiteSetting.title_prettify, remove_extraneous_space: SiteSetting.title_prettify && SiteSetting.default_locale == "en", fixes_interior_spaces: true, - strip_whitespaces: true + strip_whitespaces: true, + strip_zero_width_spaces: true } end @@ -47,6 +48,8 @@ class TextCleaner text = normalize_whitespaces(text) # Strip whitespaces text.strip! if opts[:strip_whitespaces] + # Strip zero width spaces + text.gsub!(/\u200b/, '') if opts[:strip_zero_width_spaces] text end diff --git a/spec/components/text_cleaner_spec.rb b/spec/components/text_cleaner_spec.rb index 8a25c29de82..e4a4dd2a9fc 100644 --- a/spec/components/text_cleaner_spec.rb +++ b/spec/components/text_cleaner_spec.rb @@ -159,6 +159,11 @@ describe TextCleaner do expect(TextCleaner.clean_title(" \t Hello there \n ")).to eq("Hello there") end + it "strips zero width spaces" do + expect(TextCleaner.clean_title("Hello​ ​there")).to eq("Hello there") + expect(TextCleaner.clean_title("Hello​ ​there").length).to eq(11) + end + context "title_prettify site setting is enabled" do before { SiteSetting.title_prettify = true }