Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

validateUrl: Increasing valid TLD length to 63 #115

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const validateUrl = (value, allValues) => {
const type = allValues.type;
if (allValues[type].urlType !== URL_TYPE.FULL_URL) return;
if (!value) return 'Required';
const regname = '((www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,4})';
const regname = '((www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,63})';
const ipv4 = '(((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))';
const h16 = '([0-9a-fA-F]{1,4})';
const ls32 = `((${h16}:${h16})|${ipv4})`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('validateUrl', () => {
expect(validateUrl("https://[::ff]", typeFullUrl)).toBeUndefined();
expect(validateUrl("https://[2001:db8::ff00:42:8329]:443/?foo=bar", typeFullUrl)).toBeUndefined();
expect(validateUrl("http://[64:ff9b::192.0.2.128]:80/", typeFullUrl)).toBeUndefined();
expect(validateUrl("https://org.example/", typeFullUrl)).toBeUndefined();
});

test('returns error string if invalid', () => {
Expand All @@ -53,5 +54,6 @@ describe('validateUrl', () => {
expect(validateUrl("2001:0db8:85a3:0000:0000:0000:0000:7344", typeFullUrl)).toBe(invalidText);
expect(validateUrl("http://2001:0db8:85a3:0000:0000:0000:0000:7344", typeFullUrl)).toBe(invalidText);
expect(validateUrl("http://[2001:0db8:85a3:0000:0r00:0000:0000:7344]", typeFullUrl)).toBe(invalidText);
expect(validateUrl("http://org.exampleexampleexampleexampleexampleexampleexampleexampleexampleexampleexampleexample", typeFullUrl)).toBe(invalidText);
});
});