Skip to content

Commit 53cd819

Browse files
sdetweiljens-maus
andauthored
update to detect duplicate DTSTART/DTEND in same ics event, (#348)
Co-authored-by: Jens Maus <[email protected]>
1 parent 7dd8e11 commit 53cd819

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,19 @@ END:VCALENDAR
137137
`, function(err, data) { console.log(data); });
138138
```
139139

140+
Note: When using the `ical.async.*` functions in a separate async context from your main code,
141+
errors will be thrown in that separate context. Therefore, you must wrap these function calls
142+
in try/catch blocks to properly handle any errors. For example:
143+
144+
```javascript
145+
try {
146+
const events = await ical.async.parseFile('calendar.ics');
147+
// Process events
148+
} catch (error) {
149+
console.error('Failed to parse calendar:', error);
150+
}
151+
```
152+
140153
### autodetect
141154
These are the old API examples, which still work and will be converted to the new API automatically.
142155
Functions with callbacks provided will also have better performance over the older versions even if they use the old API.

ical.js

+20-8
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ const exdateParameter = function (name) {
372372
if (typeof exdate[name].toISOString === 'function') {
373373
curr[name][exdate[name].toISOString().slice(0, 10)] = exdate[name];
374374
} else {
375-
throw new TypeError('No toISOString function in exdate[name]', exdate[name]);
375+
throw new TypeError('No toISOString function in exdate[name] = ' + exdate[name]);
376376
}
377377
}
378378
}
@@ -548,7 +548,7 @@ module.exports = {
548548
if (typeof curr.recurrenceid.toISOString === 'function') {
549549
par[curr.uid].recurrences[curr.recurrenceid.toISOString().slice(0, 10)] = recurrenceObject;
550550
} else { // Removed issue 56
551-
throw new TypeError('No toISOString function in curr.recurrenceid', curr.recurrenceid);
551+
throw new TypeError('No toISOString function in curr.recurrenceid =' + curr.recurrenceid);
552552
}
553553
}
554554

@@ -623,10 +623,10 @@ module.exports = {
623623

624624
rule = rule.replace(/\.\d{3}/, '');
625625
} catch (error) { // This should not happen, issue #56
626-
throw new Error('ERROR when trying to convert to ISOString', error);
626+
throw new Error('ERROR when trying to convert to ISOString ' + error);
627627
}
628628
} else {
629-
throw new Error('No toISOString function in curr.start', curr.start);
629+
throw new Error('No toISOString function in curr.start ' + curr.start);
630630
}
631631
}
632632

@@ -645,11 +645,23 @@ module.exports = {
645645
URL: storeParameter('url'),
646646
UID: storeParameter('uid'),
647647
LOCATION: storeParameter('location'),
648-
DTSTART(value, parameters, curr, stack) {
649-
curr = dateParameter('start')(value, parameters, curr, stack);
650-
return typeParameter('datetype')(value, parameters, curr);
648+
DTSTART(value, parameters, curr, stack, line) {
649+
// If already defined, this is a duplicate for this event
650+
if (curr.start === undefined) {
651+
curr = dateParameter('start')(value, parameters, curr, stack);
652+
return typeParameter('datetype')(value, parameters, curr);
653+
}
654+
655+
throw new Error('duplicate DTSTART encountered, line=' + line);
656+
},
657+
DTEND(value, parameters, curr, stack, line) {
658+
// If already defined, this is a duplicate for this event
659+
if (curr.end === undefined) {
660+
return dateParameter('end')(value, parameters, curr, stack);
661+
}
662+
663+
throw new Error('duplicate DTEND encountered, line=' + line);
651664
},
652-
DTEND: dateParameter('end'),
653665
EXDATE: exdateParameter('exdate'),
654666
' CLASS': storeParameter('class'), // Should there be a space in this property?
655667
TRANSP: storeParameter('transparency'),

0 commit comments

Comments
 (0)