Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions ics/with-lowercase-properties.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Test//Test//EN
BEGIN:VEVENT
dtstart:20200101T100000Z
dtend:20200101T110000Z
uid:lowercase-past@test
summary:Past event with lowercase properties
END:VEVENT
BEGIN:VEVENT
dtstart:20300101T100000Z
dtend:20300101T110000Z
uid:lowercase-future@test
summary:Future event with lowercase properties
END:VEVENT
BEGIN:VEVENT
DTSTART:20200601T120000Z
DTEND:20200601T130000Z
UID:uppercase-past@test
rrule:FREQ=YEARLY
SUMMARY:Past recurring event with lowercase rrule
END:VEVENT
END:VCALENDAR
17 changes: 9 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ export const icsFilter = (content: string, now: Date, max?: Date): string => {

function processLine(line: string): void {
line = line.trim();
const lineUpper: string = line.toUpperCase();

// --- BEGIN EVENT ---
if (line === "BEGIN:VEVENT") {
if (lineUpper === "BEGIN:VEVENT") {
inEvent = true;
eventStartIndex = findLineStartIndex(line);
if (isDevRun) {
Expand All @@ -62,7 +63,7 @@ export const icsFilter = (content: string, now: Date, max?: Date): string => {
}

// --- END EVENT ---
if (line === "END:VEVENT") {
if (lineUpper === "END:VEVENT") {
const eventEndIndex: number = findLineEndIndex(line);
if (isDevRun) {
if (inEvent && keep && rruleKeep) {
Expand Down Expand Up @@ -91,7 +92,7 @@ export const icsFilter = (content: string, now: Date, max?: Date): string => {
}

// --- PARSING ---
if (line.startsWith("SUMMARY")) {
if (lineUpper.startsWith("SUMMARY")) {
const value: string | null = extractValue(line);
if (isDevRun) {
console.log("SUMMARY:", value);
Expand All @@ -100,7 +101,7 @@ export const icsFilter = (content: string, now: Date, max?: Date): string => {
return;
}

if (line.startsWith("DTSTART")) {
if (lineUpper.startsWith("DTSTART")) {
const value: string | null = extractValue(line);
const dtStart: string | null = normalizeICSDateStr(value);
if (isDevRun) {
Expand All @@ -125,7 +126,7 @@ export const icsFilter = (content: string, now: Date, max?: Date): string => {
return;
}

if (line.startsWith("DTEND")) {
if (lineUpper.startsWith("DTEND")) {
const value: string | null = extractValue(line);
const dtEnd: string | null = normalizeICSDateStr(value);
if (isDevRun) {
Expand Down Expand Up @@ -158,7 +159,7 @@ export const icsFilter = (content: string, now: Date, max?: Date): string => {
return;
}

if (line.startsWith("RRULE")) {
if (lineUpper.startsWith("RRULE")) {
const idx: number = line.indexOf("UNTIL=");

keep = true;
Expand Down Expand Up @@ -187,7 +188,7 @@ export const icsFilter = (content: string, now: Date, max?: Date): string => {
return;
}

if (line.startsWith("RECURRENCE-ID")) {
if (lineUpper.startsWith("RECURRENCE-ID")) {
const value: string | null = extractValue(line);
const dtRecurrence: string | null = normalizeICSDateStr(value);
if (isDevRun) {
Expand Down Expand Up @@ -218,7 +219,7 @@ export const icsFilter = (content: string, now: Date, max?: Date): string => {
return;
}

if (line.startsWith("STATUS:CANCELLED")) {
if (lineUpper.startsWith("STATUS:CANCELLED")) {
keep = false;
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/tests/lowercase-properties.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import assert from "node:assert";
import { readFileSync } from "node:fs";
import { describe, test } from "node:test";

import { icsFilter } from "../index.js";

const content: string = readFileSync("./ics/with-lowercase-properties.ics", "utf-8");
const now: Date = new Date();
const filteredContent: string = icsFilter(content, now);

describe("icsFilter on ics content with lowercase property names", () => {
test("should handle lowercase DTSTART, DTEND and RRULE", () => {
assert.ok(filteredContent.includes("lowercase-future@test"), "Future event with lowercase properties should be kept");
assert.ok(!filteredContent.includes("lowercase-past@test"), "Past event with lowercase properties should be filtered out");
assert.ok(filteredContent.includes("uppercase-past@test"), "Past recurring event with lowercase rrule should be kept");
});
});