FIX: remove double quotes `"` character when building the event's mar… (#716)
This is not the best UX as user might enter an event name with double quotes and they'll be deleted once they click save. But at least it won't break their event because the double quote breaks the BBCode/Markdown. A proper fix would be to manipulate an AST instead of using regular expressions on a a string. Meta - https://meta.discourse.org/t/-/360010
This commit is contained in:
parent
b023c4d2f2
commit
743db6fe5d
|
@ -83,10 +83,11 @@ export function replaceRaw(params, raw) {
|
|||
|
||||
if (eventMatches && eventMatches[1]) {
|
||||
const markdownParams = [];
|
||||
|
||||
Object.keys(params).forEach((param) => {
|
||||
const value = params[param];
|
||||
if (value && value.length) {
|
||||
markdownParams.push(`${param}="${params[param]}"`);
|
||||
markdownParams.push(`${param}="${value.replace(/"/g, "")}"`);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
import { module, test } from "qunit";
|
||||
import { replaceRaw } from "discourse/plugins/discourse-calendar/discourse/lib/raw-event-helper";
|
||||
|
||||
module("Unit | Lib | raw-event-helper", function () {
|
||||
test("replaceRaw", function (assert) {
|
||||
const raw = 'Some text [event param1="value1"] more text';
|
||||
const params = {
|
||||
param1: "newValue1",
|
||||
param2: "value2",
|
||||
};
|
||||
|
||||
assert.strictEqual(
|
||||
replaceRaw(params, raw),
|
||||
'Some text [event param1="newValue1" param2="value2"] more text',
|
||||
"updates existing parameters and adds new ones"
|
||||
);
|
||||
|
||||
assert.false(
|
||||
replaceRaw(params, "No event tag here"),
|
||||
"returns false when no event tag is found"
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
replaceRaw({ foo: 'bar"quoted' }, '[event original="value"]'),
|
||||
'[event foo="barquoted"]',
|
||||
"escapes double quotes in parameter values"
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
replaceRaw({}, '[event param1="value1"]'),
|
||||
"[event ]",
|
||||
"handles empty params object"
|
||||
);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue