From 5a7a7aaa188c05c1191a13c6d4402be18b88108d Mon Sep 17 00:00:00 2001 From: sstent Date: Mon, 16 Feb 2026 10:17:35 -0800 Subject: [PATCH] Robust whitespace handling in URL with character code logging --- icalendar.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/icalendar.ts b/icalendar.ts index e66d838..ee5f375 100644 --- a/icalendar.ts +++ b/icalendar.ts @@ -158,10 +158,13 @@ async function getSources(): Promise { async function fetchAndParseCalendar(source: Source): Promise { let url = source.url.trim(); - // Handle internal spaces which are common in copy-pasted URLs - if (url.includes(" ")) { - console.log(`[iCalendar] URL contains spaces, encoding: "${url}"`); - url = encodeURI(url); + // Handle any whitespace (space, tabs, non-breaking spaces, etc.) + const whitespaceRegex = /\s/g; + if (whitespaceRegex.test(url)) { + const matches = url.match(whitespaceRegex); + const charCodes = matches?.map(m => m.charCodeAt(0)).join(", "); + console.log(`[iCalendar] URL contains whitespace (charCodes: ${charCodes}), encoding: "${url}"`); + url = url.replace(/\s/g, (match) => encodeURIComponent(match)); } console.log(`[iCalendar] Fetching: ${url}`);