Skip to content

Commit

Permalink
Merge pull request #34 from TesteurManiak/fix/issue_33
Browse files Browse the repository at this point in the history
Fix/issue 33
  • Loading branch information
TesteurManiak authored Oct 4, 2021
2 parents e793afd + d174630 commit 748814c
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.0.1] - 04/10/2021

* Fixed [issue #33](https://github.com/TesteurManiak/icalendar_parser/issues/33): Exception on ORGANIZER field parsing

## [1.0.0] - 22/09/2021

* Fixed `fromString` constructor
Expand Down
2 changes: 1 addition & 1 deletion lib/src/exceptions/icalendar_exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ICalendarEndException extends ICalendarFormatException {

/// Exception thrown when there is an empty line.
class EmptyLineException extends ICalendarFormatException {
const EmptyLineException(String msg) : super(msg);
const EmptyLineException() : super('Empty line are not allowed');
}

/// Exception thrown when `VERSION` is missing.
Expand Down
9 changes: 6 additions & 3 deletions lib/src/model/icalendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -223,19 +223,23 @@ class ICalendar {
Map<String, dynamic>? lastEvent = {};
String? currentName;

// Ensure first line is BEGIN:VCALENDAR
if (lines.first.trim() != 'BEGIN:VCALENDAR') {
throw ICalendarBeginException(
'The first line must be BEGIN:VCALENDAR but was ${lines.first}.');
}

// Ensure last line is END:VCALENDAR
if (lines.last.trim() != 'END:VCALENDAR') {
throw ICalendarEndException(
'The last line must be END:VCALENDAR but was ${lines.last}.');
}

for (var i = 0; i < lines.length; i++) {
final line = StringBuffer(lines[i].trim());

if (line.isEmpty && !allowEmptyLine) {
throw const EmptyLineException('Empty line are not allowed');
throw const EmptyLineException();
}

final exp = RegExp(r'^ ');
Expand All @@ -245,7 +249,7 @@ class ICalendar {
}

final dataLine = line.toString().split(':');
if (dataLine.length < 2 ||
if ((dataLine.length < 2 && !dataLine[0].contains(';')) ||
(dataLine.isNotEmpty &&
dataLine[0].toUpperCase() != dataLine[0] &&
!dataLine[0].contains(';'))) {
Expand All @@ -256,7 +260,6 @@ class ICalendar {
}

final dataName = dataLine[0].split(';');

final name = dataName[0];
dataName.removeRange(0, 1);

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: icalendar_parser
description: Package to parse iCalendar (.ics) files written in pure Dart.
version: 1.0.0
version: 1.0.1
homepage: https://github.com/TesteurManiak
repository: https://github.com/TesteurManiak/icalendar_parser

Expand Down
30 changes: 30 additions & 0 deletions test/issue_33_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:icalendar_parser/icalendar_parser.dart';
import 'package:test/test.dart';

import 'test_utils.dart';

void main() {
group('Issue #33', () {
test('No email in ORGANIZER - 1', () {
final eventText = readFileLines('organizer_no_email.ics');
final iCal = ICalendar.fromLines(eventText);
expect(iCal.data.length, 1);

final event = iCal.data[0];
final organizer = event['organizer'] as Map<String, dynamic>;
expect(organizer['name'], 'Joe Jackson');
expect(organizer['mail'], '');
});

test('No email in ORGANIZER - 2', () {
final eventText = readFileLines('organizer_no_email_2.ics');
final iCal = ICalendar.fromLines(eventText);
expect(iCal.data.length, 1);

final event = iCal.data[0];
final organizer = event['organizer'] as Map<String, dynamic>;
expect(organizer['name'], 'Joe Jackson');
expect(organizer['mail'], '');
});
});
}
2 changes: 1 addition & 1 deletion test/parsing_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void main() {
);
});

test('American History', () async {
test('American History', () {
final eventText = readFileLines('american_history.ics');
final iCalParsed = ICalendar.fromLines(eventText);
expect(
Expand Down
16 changes: 16 additions & 0 deletions test/test_resources/organizer_no_email.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:adamgibbons/ics
METHOD:PUBLISH
BEGIN:VEVENT
UID:b11ae923-9898-44ca-8f92-ed2ebe36863f
SUMMARY:Cool event
DTSTAMP:20211004T101600Z
DTSTART:20211006T063000Z
DTEND:20211006T073000Z
DESCRIPTION:Some description
STATUS:CANCELLED
ORGANIZER;CN=Joe Jackson
END:VEVENT
END:VCALENDAR
16 changes: 16 additions & 0 deletions test/test_resources/organizer_no_email_2.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:adamgibbons/ics
METHOD:PUBLISH
BEGIN:VEVENT
UID:b11ae923-9898-44ca-8f92-ed2ebe36863f
SUMMARY:Cool event
DTSTAMP:20211004T101600Z
DTSTART:20211006T063000Z
DTEND:20211006T073000Z
DESCRIPTION:Some description
CATEGORIES:APPOINTMENT
ORGANIZER;CN=Joe Jackson
END:VEVENT
END:VCALENDAR

0 comments on commit 748814c

Please sign in to comment.