lib/plist/parser.rb in plist-3.5.0 vs lib/plist/parser.rb in plist-3.6.0

- old
+ new

@@ -11,10 +11,13 @@ # === Load a plist file # This is the main point of the library: # # 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. # + Data elements are implemented as Tempfiles # @@ -44,11 +47,14 @@ def tag_start(name, attributes) @open.push PTag.mappings[name].new end def text(contents) - @open.last.text = contents if @open.last + if @open.last + @open.last.text ||= '' + @open.last.text.concat(contents) + end end def tag_end(name) last = @open.pop if @open.empty? @@ -70,15 +76,18 @@ end @listener = listener end - TEXT = /([^<]+)/ + TEXT = /([^<]+)/ + CDATA = /<!\[CDATA\[(.*?)\]\]>/ XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>*/m 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('|') start_tag = /<(#{plist_tags})([^>]*)>/i end_tag = /<\/(#{plist_tags})[^>]*>/i @@ -103,13 +112,15 @@ if (@scanner[2] =~ /\/$/) @listener.tag_end(@scanner[1]) end elsif @scanner.scan(TEXT) @listener.text(@scanner[1]) + elsif @scanner.scan(CDATA) + @listener.text(@scanner[1]) elsif @scanner.scan(end_tag) @listener.tag_end(@scanner[1]) else - raise "Unimplemented element" + raise UnimplementedElementError.new(UNIMPLEMENTED_ERROR) end end end private