Skip to content

Commit

Permalink
Merge pull request #657 from aswin-s/revert/pr-651
Browse files Browse the repository at this point in the history
Revert #651
  • Loading branch information
MonilBhavsar authored Feb 29, 2024
2 parents 9ae4a58 + d9e81dd commit 77d0b15
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 8 deletions.
6 changes: 0 additions & 6 deletions __tests__/URL-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ 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('<code>http://google.com/</code>')).toBeFalsy();
expect(regexToTest.test('<pre>http://google.com/</pre>')).toBeFalsy();
});
});

describe('Optional protocol for URL', () => {
Expand Down
3 changes: 1 addition & 2 deletions lib/Url.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ 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](?=(?<label>[-a-z0-9]*[a-z0-9]))\\k<label>?\\.)+\
(?:${TLD_REGEX})(?:\\:${ALLOWED_PORTS}|\\b|(?=_))(?!@(?:[a-z\\d-]+\\.)+[a-z]{2,})`;
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 addEscapedChar = reg => `(?:${reg}|&(?:amp|#x27);)`;
const URL_PATH_REGEX = `(?:${addEscapedChar('[.,=(+$!*]')}?\\/${addEscapedChar('[-\\w$@.+!*:(),=%~]')}*${addEscapedChar('[-\\w~@:%)]')}|\\/)*`;
const URL_PARAM_REGEX = `(?:\\?${addEscapedChar('[-\\w$@.+!*()\\/,=%{}:;\\[\\]\\|_|~]')}*)?`;
Expand Down

0 comments on commit 77d0b15

Please sign in to comment.