From adf8539f642b97beb9eff6f155d68a528b915ee5 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 23 Dec 2020 08:51:36 +1100 Subject: [PATCH] FIX: allow for final sigma in suggested usernames (#11540) Final sigma is not lower cased correctly in Ruby causing issues with routing. This works around the issue by downcasing all usernames containing a sigma using JS. --- lib/user_name_suggester.rb | 8 ++++++++ spec/components/user_name_suggester_spec.rb | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/lib/user_name_suggester.rb b/lib/user_name_suggester.rb index ecd482b4900..b367ffcbc2c 100644 --- a/lib/user_name_suggester.rb +++ b/lib/user_name_suggester.rb @@ -110,6 +110,14 @@ module UserNameSuggester if SiteSetting.unicode_usernames name.unicode_normalize! + + # TODO: Jan 2022, review if still needed + # see: https://meta.discourse.org/t/unicode-username-with-as-the-final-char-leads-to-an-error-loading-profile-page/173182 + if name.include?('Σ') + ctx = MiniRacer::Context.new + name = ctx.eval("#{name.to_s.to_json}.toLowerCase()") + ctx.dispose + end else name = ActiveSupport::Inflector.transliterate(name) end diff --git a/spec/components/user_name_suggester_spec.rb b/spec/components/user_name_suggester_spec.rb index ed1673b66bf..c20c507ccb0 100644 --- a/spec/components/user_name_suggester_spec.rb +++ b/spec/components/user_name_suggester_spec.rb @@ -128,6 +128,10 @@ describe UserNameSuggester do context "with Unicode usernames enabled" do before { SiteSetting.unicode_usernames = true } + it "normalizes unicode usernames with Σ to lowercase" do + expect(UserNameSuggester.suggest('ΣΣ\'"ΣΣ')).to eq('σς_σς') + end + it "does not transliterate" do expect(UserNameSuggester.suggest("Jørn")).to eq('Jørn') end