Skip to content

Commit

Permalink
* ext/syck/emitter.c (syck_emit_seq, syck_emit_map, syck_emit_item):
Browse files Browse the repository at this point in the history
  should output complex key mark even if map's key is empty seq/map.
  [ruby-core:7129]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9835 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
ocean committed Jan 16, 2006
1 parent 44bf6c8 commit d54f7b0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 21 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Mon Jan 16 10:13:38 2006 Hirokazu Yamamoto <[email protected]>

* ext/syck/emitter.c (syck_emit_seq, syck_emit_map, syck_emit_item):
should output complex key mark even if map's key is empty seq/map.
[ruby-core:7129]

Sat Jan 14 03:38:54 2006 Hirokazu Yamamoto <[email protected]>

* file.c (rb_file_s_chmod): avoid warning where sizeof(int) !=
Expand Down
36 changes: 15 additions & 21 deletions ext/syck/emitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,11 @@ void syck_emit_seq( SyckEmitter *e, char *tag, enum seq_style style )
syck_emitter_write( e, "[", 1 );
lvl->status = syck_lvl_iseq;
} else {
/* complex key */
if ( parent->status == syck_lvl_map && parent->ncount % 2 == 1 ) {
syck_emitter_write( e, "? ", 2 );
parent->status = syck_lvl_mapx;
}
lvl->status = syck_lvl_seq;
}
}
Expand All @@ -1019,6 +1024,11 @@ void syck_emit_map( SyckEmitter *e, char *tag, enum map_style style )
syck_emitter_write( e, "{", 1 );
lvl->status = syck_lvl_imap;
} else {
/* complex key */
if ( parent->status == syck_lvl_map && parent->ncount % 2 == 1 ) {
syck_emitter_write( e, "? ", 2 );
parent->status = syck_lvl_mapx;
}
lvl->status = syck_lvl_map;
}
}
Expand All @@ -1036,18 +1046,11 @@ void syck_emit_item( SyckEmitter *e, st_data_t n )
{
SyckLevel *parent = syck_emitter_parent_level( e );

/* seq-in-map shortcut */
if ( parent->status == syck_lvl_map && lvl->ncount == 0 ) {
/* complex key */
if ( parent->ncount % 2 == 1 ) {
syck_emitter_write( e, "?", 1 );
parent->status = syck_lvl_mapx;
/* shortcut -- the lvl->anctag check should be unneccesary but
* there is a nasty shift/reduce in the parser on this point and
* i'm not ready to tickle it. */
} else if ( lvl->anctag == 0 ) {
lvl->spaces = parent->spaces;
}
/* seq-in-map shortcut -- the lvl->anctag check should be unneccesary but
* there is a nasty shift/reduce in the parser on this point and
* i'm not ready to tickle it. */
if ( lvl->anctag == 0 && parent->status == syck_lvl_map && lvl->ncount == 0 ) {
lvl->spaces = parent->spaces;
}

/* seq-in-seq shortcut */
Expand Down Expand Up @@ -1080,15 +1083,6 @@ void syck_emit_item( SyckEmitter *e, st_data_t n )
{
SyckLevel *parent = syck_emitter_parent_level( e );

/* map-in-map */
if ( parent->status == syck_lvl_map && lvl->ncount == 0 ) {
/* complex key */
if ( parent->ncount % 2 == 1 ) {
syck_emitter_write( e, "?", 1 );
parent->status = syck_lvl_mapx;
}
}

/* map-in-seq shortcut */
if ( lvl->anctag == 0 && parent->status == syck_lvl_seq && lvl->ncount == 0 ) {
int spcs = ( lvl->spaces - parent->spaces ) - 2;
Expand Down
19 changes: 19 additions & 0 deletions test/yaml/test_yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,25 @@ def test_numeric_cycle
assert_cycle(NumericTest.new(3)) # Subclass of Numeric
end

#
# Test empty map/seq in map cycle
#
def test_empty_map_key
#
# empty seq as key
#
o = YAML.load({[]=>""}.to_yaml)
assert_equal(Hash, o.class)
assert_equal([[]], o.keys)

#
# empty map as key
#
o = YAML.load({{}=>""}.to_yaml)
assert_equal(Hash, o.class)
assert_equal([{}], o.keys)
end

end

if $0 == __FILE__
Expand Down

0 comments on commit d54f7b0

Please sign in to comment.