1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/psych/lib/psych.rb: Adding Psych::Exception

* ext/psych/parser.c: Do not allow extern_encoding to be set twice
* test/psych/test_parser.rb: test

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27882 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tenderlove 2010-05-19 03:24:13 +00:00
parent 15335f8aaa
commit c1b29ff5c6
3 changed files with 19 additions and 0 deletions

View file

@ -94,6 +94,9 @@ module Psych
# The version of libyaml Psych is using
LIBYAML_VERSION = Psych.libyaml_version.join '.'
class Exception < RuntimeError
end
###
# Load +yaml+ in to a Ruby data structure. If multiple documents are
# provided, the object contained in the first document will be returned.

View file

@ -293,8 +293,15 @@ static VALUE parse(VALUE self, VALUE yaml)
static VALUE set_external_encoding(VALUE self, VALUE encoding)
{
yaml_parser_t * parser;
VALUE exception;
Data_Get_Struct(self, yaml_parser_t, parser);
if(parser->encoding) {
exception = rb_const_get_at(mPsych, rb_intern("Exception"));
rb_raise(exception, "don't set the encoding twice!");
}
yaml_parser_set_encoding(parser, NUM2INT(encoding));
return encoding;

View file

@ -26,6 +26,15 @@ module Psych
@parser = Psych::Parser.new EventCatcher.new
end
def test_set_encoding_twice
@parser.external_encoding = Psych::Parser::UTF16LE
e = assert_raises(Psych::Exception) do
@parser.external_encoding = Psych::Parser::UTF16LE
end
assert_equal "don't set the encoding twice!", e.message
end
def test_bom
tadpole = 'おたまじゃくし'