Skip to content

Commit 5d144ba

Browse files
author
Hector Arce De Las Heras
committed
Enhance URL Validation with Additional Protocol Support
This commit improves the URL validation functionality by introducing a new protocol for validation and modifying the validation logic to accommodate this new protocol. Changes include: A new constant DATA_PROTOCOL has been introduced and included in the VALID_PROTOCOLS array for URL validation in isValidUrl.ts. This allows the validation function to check against multiple protocols. The isValidHttpUrl function in isValidUrl.ts has been updated to use the VALID_PROTOCOLS array for validation. The function now checks if the URL protocol starts with any of the valid protocols, not just HTTP_PROTOCOL. These changes enhance the robustness of the URL validation functionality.
1 parent 7eaed8e commit 5d144ba

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/utils/isValidUrl/isValidUrl.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
const HTTP_PROTOCOL = 'http';
2+
const DATA_PROTOCOL = 'data';
3+
4+
const VALID_PROTOCOLS = [HTTP_PROTOCOL, DATA_PROTOCOL];
25

36
export const isValidHttpUrl = (string: string): boolean => {
47
let parsedURL;
@@ -13,5 +16,5 @@ export const isValidHttpUrl = (string: string): boolean => {
1316
return false;
1417
}
1518

16-
return parsedURL.protocol.startsWith(HTTP_PROTOCOL);
19+
return VALID_PROTOCOLS.some(validProtocol => parsedURL.protocol.startsWith(validProtocol));
1720
};

0 commit comments

Comments
 (0)