Skip to content

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

FIX: Exclude watched-words and censored from ProseMirror markdown-it engine (#37687)

Régis Hanol6355a0100fed
diff --git a/frontend/discourse/app/static/prosemirror/lib/markdown-it.js b/frontend/discourse/app/static/prosemirror/lib/markdown-it.js
index d9f94dd763f..5a8f5dd5fc1 100644
--- a/frontend/discourse/app/static/prosemirror/lib/markdown-it.js
+++ b/frontend/discourse/app/static/prosemirror/lib/markdown-it.js
@@ -3,7 +3,7 @@ import { buildEngine } from "discourse/static/markdown-it";
let engine;
function getEngine() {
- engine ??= buildEngine(null, ["onebox"]);
+ engine ??= buildEngine(null, ["onebox", "watched-words", "censored"]);
return engine;
}
diff --git a/spec/system/composer/prosemirror_onebox_spec.rb b/spec/system/composer/prosemirror_onebox_spec.rb
index a20a58dcb63..2d250b0f187 100644
--- a/spec/system/composer/prosemirror_onebox_spec.rb
+++ b/spec/system/composer/prosemirror_onebox_spec.rb
@@ -195,15 +195,14 @@ describe "Composer - ProseMirror - Oneboxing", type: :system do
)
end
- it "does not onebox watched word links" do
+ it "does not apply watched word links to the raw content" do
visit "/t/#{topic.slug}/#{topic.id}"
find(".post-action-menu__edit").click
expect(composer).to be_opened
composer.focus
- expect(rich).to have_css("a[href='https://example.com/x']", text: "discourse")
- expect(rich).to have_no_css("a.inline-onebox")
- expect(rich).to have_no_css(".inline-onebox-loading")
+ expect(rich).to have_content("discourse")
+ expect(rich).to have_no_css("a[href='https://example.com/x']")
composer.toggle_rich_editor
diff --git a/spec/system/composer/prosemirror_watched_words_spec.rb b/spec/system/composer/prosemirror_watched_words_spec.rb
new file mode 100644
index 00000000000..f854456218a
--- /dev/null
+++ b/spec/system/composer/prosemirror_watched_words_spec.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+describe "Composer - ProseMirror - Watched Words", type: :system do
+ include_context "with prosemirror editor"
+
+ context "with watched word replacements" do
+ fab!(:topic) { Fabricate(:topic, user: current_user) }
+ fab!(:post) do
+ Fabricate(:post, topic:, user: current_user, raw: "We need to improve the ETA on this")
+ end
+ fab!(:watched_word) do
+ Fabricate(
+ :watched_word,
+ action: WatchedWord.actions[:replace],
+ word: "ETA",
+ replacement: "Estimated Time of Arrival (ETA)",
+ )
+ end
+
+ it "does not apply replacements to the raw content" do
+ visit "/t/#{topic.slug}/#{topic.id}"
+ find(".post-action-menu__edit").click
+ expect(composer).to be_opened
+ composer.focus
+
+ expect(rich).to have_content("ETA")
+ expect(rich).to have_no_content("Estimated Time of Arrival (ETA)")
+
+ composer.toggle_rich_editor
+
+ expect(composer).to have_value("We need to improve the ETA on this")
+ end
+ end
+
+ context "with censored words" do
+ fab!(:topic) { Fabricate(:topic, user: current_user) }
+ fab!(:post) do
+ Fabricate(:post, topic:, user: current_user, raw: "This is a badword in the post")
+ end
+ fab!(:watched_word) do
+ Fabricate(:watched_word, action: WatchedWord.actions[:censor], word: "badword")
+ end
+
+ it "does not censor the raw content" do
+ visit "/t/#{topic.slug}/#{topic.id}"
+ find(".post-action-menu__edit").click
+ expect(composer).to be_opened
+ composer.focus
+
+ expect(rich).to have_content("badword")
+
+ composer.toggle_rich_editor
+
+ expect(composer).to have_value("This is a badword in the post")
+ end
+ end
+end