Skip to content

Commit d84a730

Browse files
author
Hector Arce De Las Heras
committed
Update isValidURL utility function
This commit modifies the isValidURL utility function to return true when the input string starts with '/', './', or '../'. This change allows the function to correctly handle relative URLs, improving its versatility and usefulness in our codebase
1 parent 91ac593 commit d84a730

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/utils/isValidUrl/__tests__/isValidUrl.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ describe('isValidUrl utils', () => {
1212

1313
expect(isValidHttpUrl(url)).toBeTruthy();
1414
});
15+
16+
it('Relative URL is valid', () => {
17+
const url = './url/valid';
18+
19+
expect(isValidHttpUrl(url)).toBeTruthy();
20+
});
1521
});

src/utils/isValidUrl/isValidUrl.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export const isValidHttpUrl = (string: string): boolean => {
77
// eslint-disable-next-line node/no-unsupported-features/node-builtins
88
parsedURL = new URL(string);
99
} catch (e) {
10+
if (string.startsWith('/') || string.startsWith('./') || string.startsWith('../')) {
11+
return true;
12+
}
1013
return false;
1114
}
1215

0 commit comments

Comments
 (0)