Skip to content

Commit

Permalink
Merge pull request #5 from bryanoltman/master
Browse files Browse the repository at this point in the history
fix: handle comments
  • Loading branch information
electricbolt authored Jan 14, 2025
2 parents 0ffe435 + 641f513 commit 744ec1e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/src/xmlpropertylistreader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class XMLPropertyListReader {
_requireDoctype();
_requireStartElement('plist');
_logStart('<plist>');
final event = _nextEventSkipOptionalText();
final event = _nextEventSkipOptionalTexts();
if (event is! XmlStartElementEvent) {
throw _expected(
event,
Expand Down Expand Up @@ -93,7 +93,7 @@ class XMLPropertyListReader {
return list;
}
_logStart('<array>');
var event = _nextEventSkipOptionalText();
var event = _nextEventSkipOptionalTexts();
while (event is! XmlEndElementEvent) {
if (event is! XmlStartElementEvent) {
throw _expected(
Expand All @@ -102,7 +102,7 @@ class XMLPropertyListReader {
'date,integer,real,true,false)');
}
list.add(_readObject(event));
event = _nextEventSkipOptionalText();
event = _nextEventSkipOptionalTexts();
}
_logEnd('</array>');
return list;
Expand All @@ -124,7 +124,7 @@ class XMLPropertyListReader {
return dict;
}
_logStart('<dict>');
var event = _nextEventSkipOptionalText();
var event = _nextEventSkipOptionalTexts();
while (event is! XmlEndElementEvent) {
// Read key
if (event is! XmlStartElementEvent || (event.name != 'key')) {
Expand All @@ -138,15 +138,15 @@ class XMLPropertyListReader {
_requireEndElement('key');
_log('<key>$key</key>');
// Read value
event = _nextEvent();
event = _nextEventSkipOptionalTexts();
if (event is! XmlStartElementEvent) {
throw _expected(
event,
'XmlStartElementEvent (array,dict,string,data,'
'date,integer,real,true,false)');
}
dict[key] = _readObject(event);
event = _nextEventSkipOptionalText();
event = _nextEventSkipOptionalTexts();
}
_logEnd('</dict>');
return dict;
Expand Down Expand Up @@ -226,7 +226,7 @@ class XMLPropertyListReader {
/// e.g. `<string>` where `string` is the [tagName] value.
void _requireStartElement(String tagName) {
final event = _nextEventSkipOptionalText();
final event = _nextEventSkipOptionalTexts();
if (event is! XmlStartElementEvent || event.name != tagName) {
throw _expected(event, tagName);
}
Expand All @@ -238,7 +238,7 @@ class XMLPropertyListReader {
/// e.g. </string> where `string` is the [tagName] value.
void _requireEndElement(String tagName, {bool skipOptionalText = false}) {
final event = _nextEventSkipOptionalText();
final event = _nextEventSkipOptionalTexts();
if (event is! XmlEndElementEvent || event.name != tagName) {
throw _expected(event, tagName);
}
Expand Down Expand Up @@ -287,9 +287,9 @@ class XMLPropertyListReader {
/// Throws a [PropertyListReadStreamException] if the end of the xml stream is
/// encountered.
XmlEvent _nextEventSkipOptionalText() {
XmlEvent _nextEventSkipOptionalTexts() {
var event = _nextEvent();
if (event is XmlTextEvent) {
while (event is XmlTextEvent) {
event = _nextEvent();
}
return event;
Expand Down
25 changes: 25 additions & 0 deletions test/xmlpropertylistreader_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -385,5 +385,30 @@ void main() {
final o = p.parse() as String;
expect(o, equals('My string\twith a tab'));
});

test('comments', () {
const plistXml = '''
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- test -->
<key>com.apple.security.app-sandbox</key>
<!-- Hello! -->
<true/>
<!--
A multiline comment
Here's another line
-->
<key>com.apple.security.network.server</key>
<true/>
</dict>
</plist>''';
final plist = XMLPropertyListReader(plistXml);
final map = plist.parse() as Map<String, Object>;
expect(map, hasLength(2));
expect(map['com.apple.security.app-sandbox'], equals(true));
expect(map['com.apple.security.network.server'], equals(true));
});
});
}

0 comments on commit 744ec1e

Please sign in to comment.