From b68180b97bde51b2cb85923921eee2e35e0c79ed Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Wed, 15 Mar 2017 13:54:36 -0700 Subject: [PATCH] Allow ~ char in linkify path and query fragments --- src/Linkifier.test.ts | 14 ++++++++++++++ src/Linkifier.ts | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Linkifier.test.ts b/src/Linkifier.test.ts index 012b1b68..ca393c21 100644 --- a/src/Linkifier.test.ts +++ b/src/Linkifier.test.ts @@ -49,6 +49,20 @@ describe('Linkifier', () => { element.dispatchEvent(event); } + function assertLinkifiesEntireRow(uri: string, done: MochaDone) { + addRow(uri); + linkifier.linkifyRow(0); + setTimeout(() => { + assert.equal((rows[0].firstChild).tagName, 'A'); + assert.equal((rows[0].firstChild).textContent, uri); + done(); + }, 0); + } + + describe('http links', () => { + it('should allow ~ character in URI path', done => assertLinkifiesEntireRow('http://foo.com/a~b#c~d?e~f', done)); + }); + describe('validationCallback', () => { it('should enable link if true', done => { addRow('test'); diff --git a/src/Linkifier.ts b/src/Linkifier.ts index a34edbc2..df7b08a3 100644 --- a/src/Linkifier.ts +++ b/src/Linkifier.ts @@ -16,8 +16,8 @@ const ipClause = '((\\d{1,3}\\.){3}\\d{1,3})'; const localHostClause = '(localhost)'; const portClause = '(:\\d{1,5})'; const hostClause = '((' + domainBodyClause + '\\.' + tldClause + ')|' + ipClause + '|' + localHostClause + ')' + portClause + '?'; -const pathClause = '(\\/[\\/\\w\\.\\-%]*)*'; -const queryStringHashFragmentCharacterSet = '[0-9\\w\\[\\]\\(\\)\\/\\?\\!#@$%&\'*+,:;\\=\\.\\-]*'; +const pathClause = '(\\/[\\/\\w\\.\\-%~]*)*'; +const queryStringHashFragmentCharacterSet = '[0-9\\w\\[\\]\\(\\)\\/\\?\\!#@$%&\'*+,:;~\\=\\.\\-]*'; const queryStringClause = '(\\?' + queryStringHashFragmentCharacterSet + ')?'; const hashFragmentClause = '(#' + queryStringHashFragmentCharacterSet + ')?'; const negatedPathCharacterSet = '[^\\/\\w\\.\\-%]+';