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}`);