forked from GitHubMirrors/silverbullet-icalendar
Robust whitespace handling in URL with character code logging
Some checks failed
Build SilverBullet Plug / build (push) Has been cancelled
Some checks failed
Build SilverBullet Plug / build (push) Has been cancelled
This commit is contained in:
11
icalendar.ts
11
icalendar.ts
@@ -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}`);
|
||||
|
||||
Reference in New Issue
Block a user