Skip to content

Commit

Permalink
* ext/psych/parser.c: fall back to any encoding if the external
Browse files Browse the repository at this point in the history
  encoding is wrong.  [ruby-core:44163]
* test/psych/test_encoding.rb: fix test
  • Loading branch information
tenderlove committed Apr 6, 2012
1 parent f0040f6 commit 62476ce
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Sat Apr 7 02:07:00 2012 Aaron Patterson <[email protected]>

* ext/psych/parser.c: fall back to any encoding if the external
encoding is wrong. [ruby-core:44163]
* test/psych/test_encoding.rb: fix test

Fri Mar 9 06:29:22 2012 Aaron Patterson <[email protected]>

* ext/psych/lib/psych.rb (load, parse): stop parsing or loading after
Expand Down
7 changes: 4 additions & 3 deletions ext/psych/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ static VALUE transcode_io(VALUE src, int * parser_encoding)
return src;
}

rb_raise(rb_eArgError, "YAML file must be UTF-8, UTF-16LE, or UTF-16BE, not %s",
rb_enc_name(rb_enc_from_index(io_external_enc_index)));
/* If the external encoding is something we don't know how to handle,
* fall back to YAML_ANY_ENCODING. */
*parser_encoding = YAML_ANY_ENCODING;

return Qnil;
return src;
}

#endif
Expand Down
2 changes: 1 addition & 1 deletion test/psych/test_encoding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_io_shiftjis
# If the external encoding isn't utf8, utf16le, or utf16be, we cannot
# process the file.
File.open(t.path, 'r', :encoding => 'SHIFT_JIS') do |f|
assert_raises ArgumentError do
assert_raises Psych::SyntaxError do
Psych.load(f)
end
end
Expand Down

0 comments on commit 62476ce

Please sign in to comment.