diff --git a/__tests__/URL-test.js b/__tests__/URL-test.js index 1474663b..c5f01be5 100644 --- a/__tests__/URL-test.js +++ b/__tests__/URL-test.js @@ -19,6 +19,12 @@ describe('Strict URL validation', () => { expect(regexToTest.test('https://google.com:65536')).toBeFalsy(); expect(regexToTest.test('smtp://google.com')).toBeFalsy(); }); + + it('should not match urls inside tags', () => { + const regexToTest = new RegExp(`^${URL_REGEX_WITH_REQUIRED_PROTOCOL}$`, 'i'); + expect(regexToTest.test('http://google.com/')).toBeFalsy(); + expect(regexToTest.test('
http://google.com/
')).toBeFalsy(); + }); }); describe('Optional protocol for URL', () => { diff --git a/lib/Url.js b/lib/Url.js index 5b89696c..9d2a9108 100644 --- a/lib/Url.js +++ b/lib/Url.js @@ -2,7 +2,8 @@ import TLD_REGEX from './tlds'; const ALLOWED_PORTS = '([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])'; const URL_PROTOCOL_REGEX = '((ht|f)tps?:\\/\\/)'; -const URL_WEBSITE_REGEX = `${URL_PROTOCOL_REGEX}?((?:www\\.)?[a-z0-9](?:[-a-z0-9]*[a-z0-9])?\\.)+(?:${TLD_REGEX})(?:\\:${ALLOWED_PORTS}|\\b|(?=_))(?!@(?:[a-z\\d-]+\\.)+[a-z]{2,})`; +const URL_WEBSITE_REGEX = `${URL_PROTOCOL_REGEX}?((?:www\\.)?[a-z0-9](?=(?