ruby-changes:37226
From: nobu <ko1@a...>
Date: Sat, 17 Jan 2015 23:59:35 +0900 (JST)
Subject: [ruby-changes:37226] nobu:r49307 (trunk): yaml_tree.rb: fix anchor
nobu 2015-01-17 23:59:18 +0900 (Sat, 17 Jan 2015) New Revision: 49307 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49307 Log: 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 Modified files: trunk/ChangeLog trunk/ext/psych/lib/psych/visitors/yaml_tree.rb trunk/test/psych/test_string.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 49306) +++ ChangeLog (revision 49307) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Jan 17 23:59:15 2015 Nobuyoshi Nakada <nobu@r...> + + * 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@r...> * configure.in: get rid of pattern substitution, which is not Index: ext/psych/lib/psych/visitors/yaml_tree.rb =================================================================== --- ext/psych/lib/psych/visitors/yaml_tree.rb (revision 49306) +++ ext/psych/lib/psych/visitors/yaml_tree.rb (revision 49307) @@ -310,7 +310,7 @@ module Psych https://github.com/ruby/ruby/blob/trunk/ext/psych/lib/psych/visitors/yaml_tree.rb#L310 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 Index: test/psych/test_string.rb =================================================================== --- test/psych/test_string.rb (revision 49306) +++ test/psych/test_string.rb (revision 49307) @@ -66,18 +66,26 @@ module Psych https://github.com/ruby/ruby/blob/trunk/test/psych/test_string.rb#L66 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/