summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Reiter <me@reitermark.us>2019-09-04 18:08:28 +0200
committerPatrick Way <patrick.way@intersection.com>2019-09-04 12:08:28 -0400
commitbbfc4bb9b0ef5fb3a5a40e7deaf927c0ac8da977 (patch)
tree738878d8c4ceb31add6bf7fe6533bd057ada4ee0
parent1bab7acee6a0c2d4ad9b1a5ff2b05934bf043bcd (diff)
downloadplist-bbfc4bb9b0ef5fb3a5a40e7deaf927c0ac8da977.tar.gz
Add support for text inside `<![CDATA[ ... ]]>`. (#49)
* Add support for text inside `<![CDATA[ ... ]]>`. * Add tests for `CDATA`. * Remove Ruby 1.8.7 and Ree from Travis config. * Add `required_ruby_version`.
-rw-r--r--.travis.yml2
-rwxr-xr-xlib/plist/parser.rb10
-rw-r--r--plist.gemspec4
-rwxr-xr-xtest/test_parser.rb15
4 files changed, 26 insertions, 5 deletions
diff --git a/.travis.yml b/.travis.yml
index a4874b5..d0da4b3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,9 +1,7 @@
sudo: false
language: ruby
rvm:
- - ree
- jruby-18mode
- - 1.8.7
- jruby-19mode
- 1.9.3
- 2.0.0-p648 # macOS
diff --git a/lib/plist/parser.rb b/lib/plist/parser.rb
index c4fd32f..144e795 100755
--- a/lib/plist/parser.rb
+++ b/lib/plist/parser.rb
@@ -46,7 +46,10 @@ module Plist
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)
@@ -72,7 +75,8 @@ module Plist
@listener = listener
end
- TEXT = /([^<]+)/
+ TEXT = /([^<]+)/
+ CDATA = /<!\[CDATA\[(.*?)\]\]>/
XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>*/m
DOCTYPE_PATTERN = /\s*<!DOCTYPE\s+(.*?)(\[|>)/m
COMMENT_START = /\A<!--/
@@ -105,6 +109,8 @@ module Plist
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
diff --git a/plist.gemspec b/plist.gemspec
index 005c747..527c47f 100644
--- a/plist.gemspec
+++ b/plist.gemspec
@@ -20,7 +20,9 @@ Gem::Specification.new do |spec|
spec.files = %w{LICENSE.txt} + Dir.glob("lib/**/*", File::FNM_DOTMATCH).reject { |f| File.directory?(f) }
spec.require_paths = ["lib"]
- spec.add_development_dependency "bundler", "~> 1.14"
+ spec.required_ruby_version = ">= 1.9.3"
+
+ spec.add_development_dependency "bundler", ">= 1.14"
spec.add_development_dependency "rake", "~> 10.5"
spec.add_development_dependency "test-unit", "~> 1.2"
end
diff --git a/test/test_parser.rb b/test/test_parser.rb
index 94ef74e..f110a9f 100755
--- a/test/test_parser.rb
+++ b/test/test_parser.rb
@@ -67,6 +67,21 @@ class TestParser < Test::Unit::TestCase
assert_equal("2", data['key']['subkey'])
end
+ def test_cdata
+ data = Plist.parse_xml("<string><![CDATA[<unescaped/>]]></string>")
+ assert_equal('<unescaped/>', data)
+ end
+
+ def test_mixed_text_and_cdata
+ data = Plist.parse_xml('<string>text and <![CDATA[<string>unescaped</string>]]></string>')
+ assert_equal('text and <string>unescaped</string>', data)
+ end
+
+ def test_unescaped_cdata_inside_cdata
+ data = Plist.parse_xml('<string><![CDATA[<![CDATA[ ... ]]]]><![CDATA[>]]></string>')
+ assert_equal('<![CDATA[ ... ]]>', data)
+ end
+
# bug fix for decoding entities
# reported by Matthias Peick <matthias@peick.de>
def test_decode_entities