Skip to content

Commit

Permalink
chore: allow null value and undefined for validateURL (#25014)
Browse files Browse the repository at this point in the history
  • Loading branch information
secustor committed Oct 4, 2023
1 parent 4670e3b commit b73cf03
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/util/url.spec.ts
Expand Up @@ -98,8 +98,9 @@ describe('util/url', () => {
});

it('validates URLs', () => {
expect(validateUrl()).toBeFalse();
expect(validateUrl(null as never)).toBeFalse();
expect(validateUrl(undefined)).toBeFalse();
expect(validateUrl('')).toBeFalse();
expect(validateUrl(null)).toBeFalse();
expect(validateUrl('foo')).toBeFalse();
expect(validateUrl('ssh://github.com')).toBeFalse();
expect(validateUrl('http://github.com')).toBeTrue();
Expand Down
7 changes: 5 additions & 2 deletions lib/util/url.ts
Expand Up @@ -85,8 +85,11 @@ export function getQueryString(params: Record<string, any>): string {
return usp.toString();
}

export function validateUrl(url?: string, httpOnly = true): boolean {
if (!url) {
export function validateUrl(
url: string | null | undefined,
httpOnly = true
): boolean {
if (!is.nonEmptyString(url)) {
return false;
}
try {
Expand Down

0 comments on commit b73cf03

Please sign in to comment.