diff --git a/src/static/js/pad_utils.js b/src/static/js/pad_utils.js index 48f0624e9..fbb9f1637 100644 --- a/src/static/js/pad_utils.js +++ b/src/static/js/pad_utils.js @@ -60,10 +60,10 @@ const wordCharRegex = new RegExp(`[${[ const urlRegex = (() => { // TODO: wordCharRegex matches many characters that are not permitted in URIs. Are they included // here as an attempt to support IRIs? (See https://tools.ietf.org/html/rfc3987.) - const urlChar = `[-:@_.,~%+/?=&#!;()$'*${wordCharRegex.source.slice(1, -1)}]`; + const urlChar = `[-:@_.,~%+/?=&#!;()\\[\\]$'*${wordCharRegex.source.slice(1, -1)}]`; // Matches a single character that should not be considered part of the URL if it is the last // character that matches urlChar. - const postUrlPunct = '[:.,;?!)\'*]'; + const postUrlPunct = '[:.,;?!)\\]\'*]'; // Schemes that must be followed by :// const withAuth = `(?:${[ '(?:x-)?man', diff --git a/src/tests/frontend/specs/urls_become_clickable.js b/src/tests/frontend/specs/urls_become_clickable.js index f170a2a41..bb3f00b34 100644 --- a/src/tests/frontend/specs/urls_become_clickable.js +++ b/src/tests/frontend/specs/urls_become_clickable.js @@ -28,7 +28,7 @@ describe('urls', function () { }); describe('special characters inside URL', function () { - for (const char of '-:@_.,~%+/?=&#!;()$\'*') { + for (const char of '-:@_.,~%+/?=&#!;()[]$\'*') { const url = `https://etherpad.org/${char}foo`; it(url, async function () { await helper.edit(url); @@ -41,7 +41,7 @@ describe('urls', function () { }); describe('punctuation after URL is ignored', function () { - for (const char of ':.,;?!)\'*]') { + for (const char of ':.,;?!)]\'*') { const want = 'https://etherpad.org'; const input = want + char; it(input, async function () { @@ -53,21 +53,4 @@ describe('urls', function () { }); } }); - - // Square brackets are in the RFC3986 reserved set so they can legally appear in URIs, but they - // are explicitly excluded from linkification because including them is usually not desired (e.g., - // it can interfere with wiki/markdown link syntax). - describe('square brackets are excluded from linkified URLs', function () { - for (const char of '[]') { - const want = 'https://etherpad.org/'; - const input = `${want}${char}foo`; - it(input, async function () { - await helper.edit(input); - await helper.waitForPromise(() => txt().find('a').length === 1); - const link = txt().find('a'); - expect(link.attr('href')).to.be(want); - expect(link.text()).to.be(want); - }); - } - }); });