Robust whitespace handling in URL with character code logging
Some checks failed
Build SilverBullet Plug / build (push) Has been cancelled

This commit is contained in:
2026-02-16 10:17:35 -08:00
parent 7aba023818
commit 5a7a7aaa18

View File

@@ -158,10 +158,13 @@ async function getSources(): Promise<Source[]> {
async function fetchAndParseCalendar(source: Source): Promise<CalendarEvent[]> {
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}`);