From a44debdcfe0a01e2a48362b7d34848a57a5e976c Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sat, 12 Dec 2020 18:26:48 -0500 Subject: [PATCH] Add `'` and `*` to acceptable URL characters These characters are in the RFC3986 reserved set. These characters are added to the set of characters that cannot be the last character of a URL to avoid mislinkification. --- src/static/js/pad_utils.js | 4 ++-- tests/frontend/specs/urls_become_clickable.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/static/js/pad_utils.js b/src/static/js/pad_utils.js index ccd0d6771..f428da157 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/tests/frontend/specs/urls_become_clickable.js b/tests/frontend/specs/urls_become_clickable.js index c4b28fd4e..a027de9ff 100644 --- a/tests/frontend/specs/urls_become_clickable.js +++ b/tests/frontend/specs/urls_become_clickable.js @@ -31,7 +31,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); @@ -44,7 +44,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 () {