A platform for community discussion. Free, open, simple.
FIX: strip quotation marks from names in quote BBCode (#36666)
Régis Hanold29f6a76b268
diff --git a/frontend/discourse-markdown-it/src/features/bbcode-block.js b/frontend/discourse-markdown-it/src/features/bbcode-block.jsindex 78815afdb44..631bc0e4adc 100644--- a/frontend/discourse-markdown-it/src/features/bbcode-block.js+++ b/frontend/discourse-markdown-it/src/features/bbcode-block.js@@ -36,6 +36,14 @@ function trailingSpaceOnly(src, start, max) {// More can be found at https://en.wikipedia.org/wiki/Quotation_markconst QUOTATION_MARKS = [`""`, `''`, `“”`, `””`, `‘’`, `„“`, `‚’`, `«»`, `‹›`];+const QUOTATION_MARKS_PATTERN = new RegExp(+ `[${QUOTATION_MARKS.join("")}]`,+ "g"+);++export const stripQuotationMarks = (value) =>+ (value || "").replace(QUOTATION_MARKS_PATTERN, "");+const QUOTATION_MARKS_NO_MATCH = QUOTATION_MARKS.map(([a, b]) => `${a}[^${b}]+${b}`).join("|");diff --git a/frontend/discourse/app/lib/quote.js b/frontend/discourse/app/lib/quote.jsindex 874e8f75fa1..499ce88c2ac 100644--- a/frontend/discourse/app/lib/quote.js+++ b/frontend/discourse/app/lib/quote.js@@ -1,6 +1,7 @@import { helperContext } from "discourse/lib/helpers";import { prioritizeNameFallback } from "discourse/lib/settings";import { applyValueTransformer } from "discourse/lib/transformer";+import { stripQuotationMarks } from "discourse-markdown-it/features/bbcode-block";export const QUOTE_REGEXP =/\[quote=([^\]]*)\]((?:[\s\S](?!\[quote=[^\]]*\]))*?)\[\/quote\]/im;@@ -22,7 +23,7 @@ export function buildQuote(post, contents, opts = {}) {const name = prioritizeNameFallback(fullName, opts.username || post.username);const params = [- name,+ stripQuotationMarks(name),`post:${opts.post || post.post_number}`,`topic:${opts.topic || post.topic_id}`,];diff --git a/frontend/discourse/tests/unit/lib/build-quote-test.js b/frontend/discourse/tests/unit/lib/build-quote-test.jsindex f10116ea7cd..3fc7f267d48 100644--- a/frontend/discourse/tests/unit/lib/build-quote-test.js+++ b/frontend/discourse/tests/unit/lib/build-quote-test.js@@ -81,6 +81,26 @@ module("Unit | Utility | build-quote", function (hooks) {);});+ test("strips quotation marks from name", function (assert) {+ const siteSettings = getOwner(this).lookup("service:site-settings");+ siteSettings.display_name_on_posts = true;+ siteSettings.prioritize_username_in_ux = false;++ const store = getOwner(this).lookup("service:store");+ const post = store.createRecord("post", {+ cooked: "<p>hello</p>",+ username: "john",+ name: `double" single' curly"" guillemets«»`,+ post_number: 1,+ topic_id: 2,+ });++ assert.strictEqual(+ buildQuote(post, "lorem"),+ '[quote="double single curly guillemets, post:1, topic:2, username:john"]\nlorem\n[/quote]\n\n'+ );+ });+test("applying a value transformation", async function (assert) {const store = getOwner(this).lookup("service:store");const post = store.createRecord("post", {