mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 08:49:06 +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 "![](https://example.com/image.jpg)" 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 - "![](https://example.com/image.jpg)"
|
||||
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(`
|
||||
![](upload://zLd8FtsWc2ZSg3cZKIhwvhYxTcn.jpg)
|
||||
[] 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…
Reference in New Issue
Block a user