mirror of
https://github.com/discourse/discourse.git
synced 2025-04-13 15:30:13 +08:00
FIX: checklist weren't working if there was an image URL
When clicking a "checklist", we're parsing the raw to change the state of the checklist that was clicked. If there was an image URL with an empty alternative text in the raw "" it would consider the "[]" as an empty checklist item. Internal - t/124499
This commit is contained in:
parent
17c92b4b2a
commit
d3f7b3b5f9
@ -124,13 +124,19 @@ export function checklistSyntax(elem, postDecorator) {
|
||||
// make the first run go to index = 0
|
||||
let nth = -1;
|
||||
let found = false;
|
||||
|
||||
const newRaw = post.raw.replace(
|
||||
/\[(\s|\_|\-|\x|\\?\*)?\]/gi,
|
||||
/\[( |x)?\]/gi,
|
||||
(match, ignored, off) => {
|
||||
if (found) {
|
||||
return match;
|
||||
}
|
||||
|
||||
// skip empty image URLs - ""
|
||||
if (off > 0 && post.raw[off - 1] === "!") {
|
||||
return match;
|
||||
}
|
||||
|
||||
nth += blocks.every(
|
||||
(b) => b[0] >= off + match.length || off > b[1]
|
||||
);
|
||||
|
@ -1,4 +1,4 @@
|
||||
const REGEX = /\[(\s?|x|X)\]/g;
|
||||
const REGEX = /\[( |x)?\]/gi;
|
||||
|
||||
function getClasses(str) {
|
||||
switch (str) {
|
||||
|
@ -38,6 +38,19 @@ acceptance("discourse-checklist | checklist", function (needs) {
|
||||
]);
|
||||
});
|
||||
|
||||
test("does not check an image URL", async function (assert) {
|
||||
const [$elem, updated] = await prepare(`
|
||||

|
||||
[] first
|
||||
[] second
|
||||
`);
|
||||
|
||||
$elem.find(".chcklst-box")[0].click();
|
||||
|
||||
const output = await updated;
|
||||
assert.ok(output.includes("[x] first"));
|
||||
});
|
||||
|
||||
test("make checkboxes readonly while updating", async function (assert) {
|
||||
const [$elem, updated] = await prepare(`
|
||||
[ ] first
|
||||
|
Loading…
x
Reference in New Issue
Block a user