diff --git a/ChangeLog b/ChangeLog index c4af4e5102..3f5dd01a7c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sat Jan 22 10:12:30 2011 Aaron Patterson + + * ext/psych/parser.c (parse): fix assertion error when reusing a + parser after an exception has been raised + + * test/psych/test_parser.rb: test for assertion error + Sat Jan 22 04:09:22 2011 Aaron Patterson * ext/psych/lib/psych/nodes/node.rb: Make Psych::Nodes::Node diff --git a/ext/psych/parser.c b/ext/psych/parser.c index 071b8c0720..5a9d2c75f9 100644 --- a/ext/psych/parser.c +++ b/ext/psych/parser.c @@ -96,6 +96,9 @@ static VALUE parse(VALUE self, VALUE yaml) size_t line = parser->mark.line; size_t column = parser->mark.column; + yaml_parser_delete(parser); + yaml_parser_initialize(parser); + rb_raise(ePsychSyntaxError, "couldn't parse YAML at line %d column %d", (int)line, (int)column); } diff --git a/test/psych/test_parser.rb b/test/psych/test_parser.rb index cd22914d3b..ca69b1a1e3 100644 --- a/test/psych/test_parser.rb +++ b/test/psych/test_parser.rb @@ -128,6 +128,16 @@ module Psych end end + def test_syntax_error_twice + assert_raises(Psych::SyntaxError) do + @parser.parse("---\n\"foo\"\n\"bar\"\n") + end + + assert_raises(Psych::SyntaxError) do + @parser.parse("---\n\"foo\"\n\"bar\"\n") + end + end + def test_mapping_end @parser.parse("---\n!!map { key: value }") assert_called :end_mapping