match all, not just first instance of tokens to escape
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
4454db30d6
commit
9c1939b756
4 changed files with 6 additions and 6 deletions
|
@ -53,7 +53,7 @@ function parseLink(a: HTMLAnchorElement, partCreator: PartCreator) {
|
|||
if (href === a.textContent) {
|
||||
return partCreator.plain(a.textContent);
|
||||
} else {
|
||||
return partCreator.plain(`[${a.textContent.replace(/[[\\\]]/, c => "\\" + c)}](${href})`);
|
||||
return partCreator.plain(`[${a.textContent.replace(/[[\\\]]/g, c => "\\" + c)}](${href})`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ export function mdSerialize(model: EditorModel) {
|
|||
return html + part.text;
|
||||
case "room-pill":
|
||||
case "user-pill":
|
||||
return html + `[${part.text.replace(/[[\\\]]/, c => "\\" + c)}](${makeGenericPermalink(part.resourceId)})`;
|
||||
return html + `[${part.text.replace(/[[\\\]]/g, c => "\\" + c)}](${makeGenericPermalink(part.resourceId)})`;
|
||||
}
|
||||
}, "");
|
||||
}
|
||||
|
|
|
@ -157,11 +157,11 @@ describe('editor/deserialize', function() {
|
|||
expect(parts[2]).toStrictEqual({type: "plain", text: "!"});
|
||||
});
|
||||
it('user pill with displayname containing opening square bracket', function() {
|
||||
const html = "Hi <a href=\"https://matrix.to/#/@alice:hs.tld\">Alice[</a>!";
|
||||
const html = "Hi <a href=\"https://matrix.to/#/@alice:hs.tld\">Alice[[</a>!";
|
||||
const parts = normalize(parseEvent(htmlMessage(html), createPartCreator()));
|
||||
expect(parts.length).toBe(3);
|
||||
expect(parts[0]).toStrictEqual({type: "plain", text: "Hi "});
|
||||
expect(parts[1]).toStrictEqual({type: "user-pill", text: "Alice[", resourceId: "@alice:hs.tld"});
|
||||
expect(parts[1]).toStrictEqual({type: "user-pill", text: "Alice[[", resourceId: "@alice:hs.tld"});
|
||||
expect(parts[2]).toStrictEqual({type: "plain", text: "!"});
|
||||
});
|
||||
it('user pill with displayname containing closing square bracket', function() {
|
||||
|
|
|
@ -51,9 +51,9 @@ describe('editor/serialize', function() {
|
|||
});
|
||||
it('displaynames containing an opening square bracket work', function() {
|
||||
const pc = createPartCreator();
|
||||
const model = new EditorModel([pc.userPill("Displayname[", "@user:server")]);
|
||||
const model = new EditorModel([pc.userPill("Displayname[[", "@user:server")]);
|
||||
const html = htmlSerializeIfNeeded(model, {});
|
||||
expect(html).toBe("<a href=\"https://matrix.to/#/@user:server\">Displayname[</a>");
|
||||
expect(html).toBe("<a href=\"https://matrix.to/#/@user:server\">Displayname[[</a>");
|
||||
});
|
||||
it('displaynames containing a closing square bracket work', function() {
|
||||
const pc = createPartCreator();
|
||||
|
|
Loading…
Reference in a new issue