Skip to content

Commit

Permalink
Allow for no whitespace at end of xml plist
Browse files Browse the repository at this point in the history
  • Loading branch information
Electric Bolt committed Jan 26, 2022
1 parent 2184003 commit 8cf5d22
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/src/xmlpropertylistreader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class XMLPropertyListReader {
'date,integer,real,true,false)');
}
var result = _readObject(event);
_requireEndElement('plist');
_requireEndElement('plist', skipOptionalText: true);
_logEnd('</plist>');
return result;
}
Expand Down Expand Up @@ -231,12 +231,14 @@ class XMLPropertyListReader {
/// name [tagName], otherwise throws a [PropertyListReadStreamException].
/// e.g. </string> where `string` is the [tagName] value.
void _requireEndElement(String tagName) {
void _requireEndElement(String tagName, {bool skipOptionalText = false}) {
var event = _nextEventSkipOptionalText();
if (!(event is XmlEndElementEvent) || event.name != tagName) {
throw _expected(event, tagName);
}
_skipOptionalText();
if (!skipOptionalText) {
_skipOptionalText();
}
}

/// Ensures the next element from the xml stream is a DOCTYPE, otherwise
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: propertylistserialization
description: iOS compatible plist serialization and deserialization library for Dart.
version: 1.1.0
version: 1.1.1
homepage: https://github.com/electricbolt/dartpropertylistserialization

environment:
Expand Down
13 changes: 13 additions & 0 deletions test/xmlpropertylistreader_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ void main() {

group('array', ()
{
test('emptyArrayNoFinalWhitespace', () {
var template = '<?xml version="1.0" encoding="UTF-8"?>\n'
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n'
'<plist version="1.0">\n'
'\t<array>\n'
'\t</array>\n'
'</plist>';

var p = XMLPropertyListReader(template);
var o = p.parse() as List<Object>;
expect(o.length, equals(0));
});

test('emptyArray', () {
var template = '<?xml version="1.0" encoding="UTF-8"?>\n'
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n'
Expand Down

0 comments on commit 8cf5d22

Please sign in to comment.