From 1909c2a8d19a76faa5084faeb6212e2c81b3f9d6 Mon Sep 17 00:00:00 2001 From: Aditya Sharma Date: Tue, 12 Aug 2025 21:33:25 -0700 Subject: [PATCH] fix: normalize feed URL protocols --- scripts/pretest.js | 2 +- tests/urlHelpers.test.js | 4 ++++ utils/url-helpers.ts | 6 +++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/pretest.js b/scripts/pretest.js index 8fbf182..ecb3b64 100644 --- a/scripts/pretest.js +++ b/scripts/pretest.js @@ -5,7 +5,7 @@ const modules = [ ]; try { execSync(`rm -rf compiled-tests && mkdir compiled-tests`); - execSync(`npx tsc ${modules.join(' ')} --module commonjs --target es2017 --outDir compiled-tests`, { stdio: 'inherit' }); + execSync(`npx tsc ${modules.join(' ')} --module commonjs --target es2017 --skipLibCheck --outDir compiled-tests`, { stdio: 'inherit' }); } catch (e) { console.error('Failed to compile test modules', e); process.exit(1); diff --git a/tests/urlHelpers.test.js b/tests/urlHelpers.test.js index 1ea5500..a78bfd7 100644 --- a/tests/urlHelpers.test.js +++ b/tests/urlHelpers.test.js @@ -6,6 +6,10 @@ test('removes protocol and trailing slash', () => { assert.strictEqual(normalizeFeedUrl('https://example.com/'), 'example.com'); }); +test('removes protocol regardless of case', () => { + assert.strictEqual(normalizeFeedUrl('HTTP://Example.com'), 'Example.com'); +}); + test('normalizes multiple slashes', () => { assert.strictEqual(normalizeFeedUrl('https://example.com//a//b'), 'example.com/a/b'); }); diff --git a/utils/url-helpers.ts b/utils/url-helpers.ts index ff0ac4b..fdc1a2a 100644 --- a/utils/url-helpers.ts +++ b/utils/url-helpers.ts @@ -4,8 +4,8 @@ export const normalizeFeedUrl = (url: string | null): string => { // First decode to handle any encoded URLs const decoded = decodeURIComponent(url); return decoded - // Remove protocol - .replace(/^https?:\/\//, '') + // Remove protocol (case-insensitive) + .replace(/^https?:\/\//i, '') // Remove trailing slashes .replace(/\/+$/, '') // Normalize multiple slashes @@ -14,4 +14,4 @@ export const normalizeFeedUrl = (url: string | null): string => { console.warn('Error normalizing URL:', error); return url.replace(/\/+$/, ''); } -}; \ No newline at end of file +};