From 7b876e65ed79d9ca4a22f7731a463ee30e35b30b Mon Sep 17 00:00:00 2001 From: tenderlove Date: Sat, 22 Jan 2011 02:23:12 +0000 Subject: [PATCH] * ext/psych/parser.c (parse): fixing off-by-one error on line numbers in parse exceptions. [ruby-core:34690] * test/psych/test_parser.rb: test for error git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30628 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ ext/psych/parser.c | 2 +- test/psych/test_parser.rb | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a9b816b6e8..fd5b181d6a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sat Jan 22 11:21:40 2011 Aaron Patterson + + * ext/psych/parser.c (parse): fixing off-by-one error on line numbers + in parse exceptions. [ruby-core:34690] + + * test/psych/test_parser.rb: test for error + Sat Jan 22 10:25:19 2011 Aaron Patterson * ext/psych/parser.c (parse): add the file name to the exception when diff --git a/ext/psych/parser.c b/ext/psych/parser.c index 7bfdf4af90..05b493a853 100644 --- a/ext/psych/parser.c +++ b/ext/psych/parser.c @@ -95,7 +95,7 @@ static VALUE parse(VALUE self, VALUE yaml) while(!done) { if(!yaml_parser_parse(parser, &event)) { VALUE path; - size_t line = parser->mark.line; + size_t line = parser->mark.line + 1; size_t column = parser->mark.column; if(rb_respond_to(yaml, id_path)) diff --git a/test/psych/test_parser.rb b/test/psych/test_parser.rb index a60a0c6d86..3894eadb4e 100644 --- a/test/psych/test_parser.rb +++ b/test/psych/test_parser.rb @@ -155,6 +155,21 @@ module Psych assert_match "(#{io.path}):", e.message end + # ruby-core:34690 + def test_exception_line + e = assert_raises(Psych::SyntaxError) do + @parser.parse(<<-eoyaml) +# based on "SGML/XML character entity reference" at http://www.bitjungle.com/isoent/ +# +--- +#DOUBLE LOW-9 QUOTATION MARK +#requires fontenc:T1 +ldquor: ,, + eoyaml + end + assert_match 'line 6', e.message + end + def test_mapping_end @parser.parse("---\n!!map { key: value }") assert_called :end_mapping