diff --git a/__tests__/Str-test.js b/__tests__/Str-test.js index 463ee3df..51f68aa6 100644 --- a/__tests__/Str-test.js +++ b/__tests__/Str-test.js @@ -104,6 +104,7 @@ describe('Str.sanitizeURL', () => { expect(Str.sanitizeURL('https://GOOgle.com')).toBe('https://google.com'); +expect(Str.sanitizeURL('FOO.com/blah_BLAH', 'http')).toBe('http://foo.com/blah_BLAH'); +expect(Str.sanitizeURL('example.com', 'http')).toBe('http://example.com'); + expect(Str.sanitizeURL('https://example.com', 'http')).toBe('http://example.com'); expect(Str.sanitizeURL('http://FOO.com/blah_BLAH')).toBe('http://foo.com/blah_BLAH'); expect(Str.sanitizeURL('HTtp://FOO.com/blah_BLAH')).toBe('http://foo.com/blah_BLAH'); }); diff --git a/lib/str.ts b/lib/str.ts index d32fbfa9..441ce1f7 100644 --- a/lib/str.ts +++ b/lib/str.ts @@ -971,16 +971,16 @@ const Str = { * Formats a URL by converting the domain name to lowercase and adding the missing 'https://' protocol. * * @param url The URL to be formatted - * @param scheme The Scheme to use in the URL + * @param defaultScheme The Scheme to use in the URL * @returns The formatted URL */ - sanitizeURL(url: string, scheme = 'https'): string { + sanitizeURL(url: string, defaultScheme = 'https'): string { const regex = new RegExp(`^${UrlPatterns.URL_REGEX}$`, 'i'); const match = regex.exec(url); if (!match) { return url; } - const website = match[3] ? match[2] : `${scheme}://${match[2]}`; + const website = match[3] ? match[2] : `${defaultScheme}://${match[2]}`; return website.toLowerCase() + this.cutBefore(match[1], match[2]); },