A platform for community discussion. Free, open, simple.
FIX: rich editor mention case sensitivity (#33222)
Renato Atilio81b851824f8e
diff --git a/app/assets/javascripts/discourse/app/static/prosemirror/extensions/mention.js b/app/assets/javascripts/discourse/app/static/prosemirror/extensions/mention.jsindex 748b32135fb..dbb8fe0e18f 100644--- a/app/assets/javascripts/discourse/app/static/prosemirror/extensions/mention.js+++ b/app/assets/javascripts/discourse/app/static/prosemirror/extensions/mention.js@@ -163,8 +163,17 @@ async function fetchMentions(names) {data: { names },});+ const lowerGroupNames = Object.keys(response.groups).map((groupName) =>+ groupName.toLowerCase()+ );+names.forEach((name) => {- if (response.users.includes(name) || response.groups[name]) {+ const lowerName = name.toLowerCase();++ if (+ response.users.includes(lowerName) ||+ lowerGroupNames.includes(lowerName)+ ) {VALID_MENTIONS.add(name);} else {INVALID_MENTIONS.add(name);diff --git a/spec/system/composer/prosemirror_editor_spec.rb b/spec/system/composer/prosemirror_editor_spec.rbindex 1844b653991..2d2cfd57d37 100644--- a/spec/system/composer/prosemirror_editor_spec.rb+++ b/spec/system/composer/prosemirror_editor_spec.rb@@ -848,6 +848,10 @@ describe "Composer - ProseMirror editor", type: :system dodescribe "with mentions" dofab!(:post)fab!(:topic) { post.topic }+ fab!(:mixed_case_user) { Fabricate(:user, username: "TestUser_123") }+ fab!(:mixed_case_group) do+ Fabricate(:group, name: "TestGroup_ABC", mentionable_level: Group::ALIAS_LEVELS[:everyone])+ endbefore doDraft.set(@@ -884,6 +888,32 @@ describe "Composer - ProseMirror editor", type: :system doexpect(rich).to have_css("a.mention[data-valid='true']", text: user.username)expect(rich).to have_css("a.mention[data-valid='false']", text: "@unknown")end++ it "validates mentions case-insensitively" do+ open_composer_and_toggle_rich_editor++ composer.type_content("Hey @testuser_123 and @TESTUSER_123 ")++ expect(rich).to have_css("a.mention[data-valid='true']", text: "testuser_123")+ expect(rich).to have_css("a.mention[data-valid='true']", text: "TESTUSER_123")++ composer.type_content("and @InvalidUser ")++ expect(rich).to have_css("a.mention[data-valid='false']", text: "@InvalidUser")+ end++ it "validates group mentions case-insensitively" do+ open_composer_and_toggle_rich_editor++ composer.type_content("Hey @testgroup_abc and @TESTGROUP_ABC ")++ expect(rich).to have_css("a.mention[data-valid='true']", text: "testgroup_abc")+ expect(rich).to have_css("a.mention[data-valid='true']", text: "TESTGROUP_ABC")++ composer.type_content("and @InvalidGroup ")++ expect(rich).to have_css("a.mention[data-valid='false']", text: "@InvalidGroup")+ endenddescribe "link toolbar" do