Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

From yaml, register a newly created String with aliases. To yaml, register Strings containing ivars with aliases. #69

Merged
merged 1 commit into from

2 participants

Joe Rafaniello Aaron Patterson
Joe Rafaniello

No description provided.

Joe Rafaniello

Fixes #68

Aaron Patterson tenderlove merged commit 2b4f76f into from
Sandor Szücs szuecs referenced this pull request from a commit in szuecs/ruby
Aaron Patterson * ext/psych/lib/psych/visitors/to_ruby.rb: strings with YAML anchors
  are properly referenced. Patched by Joe Rafaniello via Github:
    tenderlove/psych#69
* ext/psych/lib/psych/visitors/yaml_tree.rb: ditto
* test/psych/test_alias_and_anchor.rb: test for change

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36414 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
7d1f53e
Aaron Patterson tenderlove referenced this pull request from a commit in tenderlove/ruby
Aaron Patterson * ext/psych/lib/psych/visitors/to_ruby.rb: strings with YAML anchors
  are properly referenced. Patched by Joe Rafaniello via Github:
    tenderlove/psych#69
* ext/psych/lib/psych/visitors/yaml_tree.rb: ditto
* test/psych/test_alias_and_anchor.rb: test for change

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36414 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
e7ecced
Jerome Leaky h4dex referenced this pull request from a commit in h4dex/ruby
Aaron Patterson merge revision(s) r36583, r36458, r36414, r36103, r35690, r35681, r35…
…658, r35657, r35655, r35492: [Backport #6815]

    * ext/psych/lib/psych.rb: updated to released version.

    * ext/psych/psych.gemspec: ditto

    * ext/psych/emitter.c (initialize): allow a configuration object to be
      passed to the constructor so that mutation isn't required after
      instantiation.

    * ext/psych/lib/psych/handler.rb: add configuration object

    * ext/psych/lib/psych/visitors/emitter.rb: use configuration object if
      extra configuration is present.

    * ext/psych/lib/psych/visitors/to_ruby.rb: strings with YAML anchors
      are properly referenced. Patched by Joe Rafaniello via Github:
        tenderlove/psych#69
    * ext/psych/lib/psych/visitors/yaml_tree.rb: ditto
    * test/psych/test_alias_and_anchor.rb: test for change

    * ext/psych/lib/psych.rb: bumping psych to 1.3.3
    * ext/psych/psych.gemspec: ditto

    * ext/psych/extconf.rb: Use an exception instaed of bare abort.

    * ext/psych/parser.c (transcode_string): fix encoding index names.
      Thanks markizko for reporting.

    * ext/psych/lib/psych/visitors/to_ruby.rb: fix a bug with string
      subclass dumping and loading.

    * test/psych/test_array.rb: pertinent tests

    * test/psych/test_string.rb: ditto

    * ext/psych/lib/psych/visitors/to_ruby.rb: convert omap tagged maps to
      Psych::Omap objects rather than hashes. [Bug #6425]

    * test/psych/test_omap.rb: pertinent test.

    * ext/psych/lib/psych/visitors/yaml_tree.rb: keep a reference to
      custom coders so that GC does not impact dumped yaml reference ids.

    * ext/psych/lib/psych/json/yaml_events.rb: implicit styles should not
      be changeable for JSON events.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@36654 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
6b3bac2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 13, 2012
  1. Joe Rafaniello

    From yaml, register a newly created String with aliases. To yaml, reg…

    jrafanie authored
    …ister Strings containing ivars with aliases.
This page is out of date. Refresh to see the latest.
1  lib/psych/visitors/to_ruby.rb
View
@@ -148,6 +148,7 @@ def visit_Psych_Nodes_Mapping o
if klass
string = klass.allocate.replace string
+ register(o, string)
end
init_with(string, members.map { |k,v| [k.to_s.sub(/^@/, ''),v] }, o)
2  lib/psych/visitors/yaml_tree.rb
View
@@ -254,7 +254,7 @@ def visit_String o
maptag = '!ruby/string'
maptag << ":#{o.class}" unless o.class == ::String
- @emitter.start_mapping nil, maptag, false, Nodes::Mapping::BLOCK
+ register o, @emitter.start_mapping(nil, maptag, false, Nodes::Mapping::BLOCK)
@emitter.scalar 'str', nil, nil, true, false, Nodes::Scalar::ANY
@emitter.scalar str, nil, tag, plain, quote, style
70 test/psych/test_alias_and_anchor.rb
View
@@ -1,5 +1,13 @@
require 'psych/helper'
+class ObjectWithInstanceVariables
+ attr_accessor :var1, :var2
+end
+
+class SubStringWithInstanceVariables < String
+ attr_accessor :var1
+end
+
module Psych
class TestAliasAndAnchor < TestCase
def test_mri_compatibility
@@ -14,6 +22,40 @@ def test_mri_compatibility
result.each {|el| assert_same(result[0], el) }
end
+ def test_mri_compatibility_object_with_ivars
+ yaml = <<EOYAML
+---
+- &id001 !ruby/object:ObjectWithInstanceVariables
+ var1: test1
+ var2: test2
+- *id001
+- *id001
+EOYAML
+
+ result = Psych.load yaml
+ result.each do |el|
+ assert_same(result[0], el)
+ assert_equal('test1', el.var1)
+ assert_equal('test2', el.var2)
+ end
+ end
+
+ def test_mri_compatibility_substring_with_ivars
+ yaml = <<EOYAML
+---
+- &id001 !str:SubStringWithInstanceVariables
+ str: test
+ "@var1": test
+- *id001
+- *id001
+EOYAML
+ result = Psych.load yaml
+ result.each do |el|
+ assert_same(result[0], el)
+ assert_equal('test', el.var1)
+ end
+ end
+
def test_anchor_alias_round_trip
o = Object.new
original = [o,o,o]
@@ -22,5 +64,33 @@ def test_anchor_alias_round_trip
result = Psych.load yaml
result.each {|el| assert_same(result[0], el) }
end
+
+ def test_anchor_alias_round_trip_object_with_ivars
+ o = ObjectWithInstanceVariables.new
+ o.var1 = 'test1'
+ o.var2 = 'test2'
+ original = [o,o,o]
+
+ yaml = Psych.dump original
+ result = Psych.load yaml
+ result.each do |el|
+ assert_same(result[0], el)
+ assert_equal('test1', el.var1)
+ assert_equal('test2', el.var2)
+ end
+ end
+
+ def test_anchor_alias_round_trip_substring_with_ivars
+ o = SubStringWithInstanceVariables.new
+ o.var1 = 'test'
+ original = [o,o,o]
+
+ yaml = Psych.dump original
+ result = Psych.load yaml
+ result.each do |el|
+ assert_same(result[0], el)
+ assert_equal('test', el.var1)
+ end
+ end
end
end
Something went wrong with that request. Please try again.