diff --git a/CliClient/tests/markdownUtils.js b/CliClient/tests/markdownUtils.js index 154a3a522f1..5dc1dc610a2 100644 --- a/CliClient/tests/markdownUtils.js +++ b/CliClient/tests/markdownUtils.js @@ -49,4 +49,19 @@ describe('markdownUtils', function() { } })); + it('escape a markdown link (title)', asyncTest(async () => { + + const testCases = [ + ['Helmut K. C. Tessarek', 'Helmut K. C. Tessarek'], + ['Helmut (K. C.) Tessarek', 'Helmut (K. C.) Tessarek'], + ['Helmut [K. C.] Tessarek', 'Helmut \\[K. C.\\] Tessarek'], + ]; + + for (let i = 0; i < testCases.length; i++) { + const md = testCases[i][0]; + const expected = testCases[i][1]; + expect(markdownUtils.escapeTitleText(md)).toBe(expected); + } + })); + }); diff --git a/ReactNativeClient/lib/markdownUtils.js b/ReactNativeClient/lib/markdownUtils.js index 6ac4301b9bc..8f1110b7c95 100644 --- a/ReactNativeClient/lib/markdownUtils.js +++ b/ReactNativeClient/lib/markdownUtils.js @@ -9,6 +9,11 @@ const markdownUtils = { return text.replace(/(\[|\]|\(|\))/g, '_'); }, + // Titles for markdown links only need escaping for [ and ] + escapeTitleText(text) { + return text.replace(/(\[|\])/g, '\\$1'); + }, + escapeLinkUrl(url) { url = url.replace(/\(/g, '%28'); url = url.replace(/\)/g, '%29'); diff --git a/ReactNativeClient/lib/models/BaseItem.js b/ReactNativeClient/lib/models/BaseItem.js index 5427c24facf..1f194167811 100644 --- a/ReactNativeClient/lib/models/BaseItem.js +++ b/ReactNativeClient/lib/models/BaseItem.js @@ -761,7 +761,7 @@ class BaseItem extends BaseModel { const output = []; output.push('['); - output.push(markdownUtils.escapeLinkText(item.title)); + output.push(markdownUtils.escapeTitleText(item.title)); output.push(']'); output.push(`(:/${item.id})`); return output.join('');