diff --git a/__tests__/URL-test.js b/__tests__/URL-test.js index 1474663b..dd42d45a 100644 --- a/__tests__/URL-test.js +++ b/__tests__/URL-test.js @@ -25,6 +25,7 @@ describe('Strict URL validation', () => { it('correctly tests valid urls', () => { const regexToTest = new RegExp(`^${URL_REGEX}$`, 'i'); expect(regexToTest.test('google.com/')).toBeTruthy(); + expect(regexToTest.test('x.com')).toBeTruthy(); expect(regexToTest.test('https://google.com/')).toBeTruthy(); expect(regexToTest.test('ftp://google.com/')).toBeTruthy(); expect(regexToTest.test('we.are.expensify.com/how-we-got-here')).toBeTruthy(); diff --git a/lib/Url.js b/lib/Url.js index 5b89696c..f4e4aa5b 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](?=(?