summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Arnoud <laurent@spkdev.net>2019-12-29 17:04:27 +0000
committerPatrick Way <patrick@hexane.org>2019-12-29 12:04:27 -0500
commit96758e813d3e3ff1d03073e8b7badb2535c5ab76 (patch)
tree242570eefbc0517f1bc94a2054128fd1f210fde1
parentc4ea1afce01d53571525460784285e9effa96568 (diff)
downloadplist-96758e813d3e3ff1d03073e8b7badb2535c5ab76.tar.gz
Add error unimplemented (#51)
* Add test for unimplemented error * Add UnimplementedElementError exception
-rwxr-xr-xlib/plist/parser.rb7
-rwxr-xr-xtest/test_parser.rb6
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/plist/parser.rb b/lib/plist/parser.rb
index 144e795..f325988 100755
--- a/lib/plist/parser.rb
+++ b/lib/plist/parser.rb
@@ -13,6 +13,9 @@
#
# r = Plist.parse_xml(filename_or_xml)
module Plist
+ # Raised when an element is not implemented
+ class UnimplementedElementError < RuntimeError; end
+
# Note that I don't use these two elements much:
#
# + Date elements are returned as DateTime objects.
@@ -81,6 +84,8 @@ module Plist
DOCTYPE_PATTERN = /\s*<!DOCTYPE\s+(.*?)(\[|>)/m
COMMENT_START = /\A<!--/
COMMENT_END = /.*?-->/m
+ UNIMPLEMENTED_ERROR = 'Unimplemented element. ' \
+ 'Consider reporting via https://github.com/patsplat/plist/issues'
def parse
plist_tags = PTag.mappings.keys.join('|')
@@ -114,7 +119,7 @@ module Plist
elsif @scanner.scan(end_tag)
@listener.tag_end(@scanner[1])
else
- raise "Unimplemented element"
+ raise UnimplementedElementError.new(UNIMPLEMENTED_ERROR)
end
end
end
diff --git a/test/test_parser.rb b/test/test_parser.rb
index f110a9f..7b692a5 100755
--- a/test/test_parser.rb
+++ b/test/test_parser.rb
@@ -116,4 +116,10 @@ class TestParser < Test::Unit::TestCase
assert_equal("\u0099", data["non-ascii-but-utf8-character"])
end
end
+
+ def test_unimplemented_element
+ assert_raise Plist::UnimplementedElementError do
+ Plist.parse_xml('<string>Fish &amp; Chips</tring>')
+ end
+ end
end