aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-17 14:59:18 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-17 14:59:18 +0000
commitf59ce53f265dd2b2ada018a911d917a3eaeace99 (patch)
treee8d70f35924b6fadf4421a2f5cb8ca2438e61545
parent748372be9715f89eabadf2840604ea24f3d0e026 (diff)
downloadruby-f59ce53f265dd2b2ada018a911d917a3eaeace99.tar.gz
yaml_tree.rb: fix anchor
* ext/psych/lib/psych/visitors/yaml_tree.rb (visit_String): anchors like `\Z` are not valid inside character class. use negative-lookahead instead. Fixes: https://github.com/tenderlove/psych/issues/221 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49307 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--ext/psych/lib/psych/visitors/yaml_tree.rb2
-rw-r--r--test/psych/test_string.rb24
3 files changed, 24 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 8d8663150b..97eed219b7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Sat Jan 17 23:59:15 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/psych/lib/psych/visitors/yaml_tree.rb (visit_String):
+ anchors like `\Z` are not valid inside character class. use
+ negative-lookahead instead.
+ Fixes: https://github.com/tenderlove/psych/issues/221
+
Sat Jan 17 23:42:27 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in: get rid of pattern substitution, which is not
diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb
index c1039c6db0..8841cb0fc9 100644
--- a/ext/psych/lib/psych/visitors/yaml_tree.rb
+++ b/ext/psych/lib/psych/visitors/yaml_tree.rb
@@ -310,7 +310,7 @@ module Psych
style = Nodes::Scalar::LITERAL
plain = false
quote = false
- elsif o =~ /\n[^\Z]/ # match \n except blank line at the end of string
+ elsif o =~ /\n(?!\Z)/ # match \n except blank line at the end of string
style = Nodes::Scalar::LITERAL
elsif o == '<<'
style = Nodes::Scalar::SINGLE_QUOTED
diff --git a/test/psych/test_string.rb b/test/psych/test_string.rb
index df8fb986bb..a8ae55cabe 100644
--- a/test/psych/test_string.rb
+++ b/test/psych/test_string.rb
@@ -66,18 +66,26 @@ module Psych
end
def test_literal_when_inner_and_final_line_break
- str = "Lorem ipsum\ndolor\n"
- yaml = Psych.dump str, line_width: 12
- assert_match /---\s*|\n(.*\n){2}\Z/, yaml
- assert_equal str, Psych.load(yaml)
+ [
+ "Lorem ipsum\ndolor\n",
+ "Lorem ipsum\nZolor\n",
+ ].each do |str|
+ yaml = Psych.dump str, line_width: 12
+ assert_match /---\s*\|\n(.*\n){2}\Z/, yaml
+ assert_equal str, Psych.load(yaml)
+ end
end
# http://yaml.org/spec/1.2/2009-07-21/spec.html#id2593651
def test_literal_strip_when_inner_line_break_and_no_final_line_break
- str = "Lorem ipsum\ndolor"
- yaml = Psych.dump str, line_width: 12
- assert_match /---\s*|-\n(.*\n){2}\Z/, yaml
- assert_equal str, Psych.load(yaml)
+ [
+ "Lorem ipsum\ndolor",
+ "Lorem ipsum\nZolor",
+ ].each do |str|
+ yaml = Psych.dump str, line_width: 12
+ assert_match /---\s*\|-\n(.*\n){2}\Z/, yaml
+ assert_equal str, Psych.load(yaml)
+ end
end
def test_cycle_x