ruby-changes:43805
From: nobu <ko1@a...>
Date: Fri, 12 Aug 2016 12:50:38 +0900 (JST)
Subject: [ruby-changes:43805] nobu:r55878 (trunk): error.c: fix newline in syntax error
nobu 2016-08-12 12:50:33 +0900 (Fri, 12 Aug 2016) New Revision: 55878 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55878 Log: error.c: fix newline in syntax error * error.c (rb_syntax_error_append): fix newline in syntax error message to the beginning, not after file name and line number. [Feature #11951] Modified files: trunk/ChangeLog trunk/error.c trunk/test/ruby/test_iseq.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 55877) +++ ChangeLog (revision 55878) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Aug 12 12:50:31 2016 Nobuyoshi Nakada <nobu@r...> + + * error.c (rb_syntax_error_append): fix newline in syntax error + message to the beginning, not after file name and line number. + [Feature #11951] + Thu Aug 11 16:24:23 2016 nerdinand <nerdinand@n...> * compar.c (cmp_clamp): Introduce Comparable#clamp. [Feature #10594] Index: test/ruby/test_iseq.rb =================================================================== --- test/ruby/test_iseq.rb (revision 55877) +++ test/ruby/test_iseq.rb (revision 55878) @@ -234,6 +234,9 @@ class TestISeq < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_iseq.rb#L234 end end assert_equal([m1, e1.message], [m2, e2.message], feature11951) + e1, e2 = e1.message.lines + assert_send([e1, :start_with?, __FILE__]) + assert_send([e2, :start_with?, __FILE__]) end def test_translate_by_object Index: error.c =================================================================== --- error.c (revision 55877) +++ error.c (revision 55878) @@ -106,16 +106,16 @@ rb_syntax_error_append(VALUE exc, VALUE https://github.com/ruby/ruby/blob/trunk/error.c#L106 } else { VALUE mesg; - const char *pre = NULL; if (NIL_P(exc)) { mesg = rb_enc_str_new(0, 0, enc); exc = rb_class_new_instance(1, &mesg, rb_eSyntaxError); } else { mesg = rb_attr_get(exc, idMesg); - pre = "\n"; + if (RSTRING_LEN(mesg) > 0 && *(RSTRING_END(mesg)-1) != '\n') + rb_str_cat_cstr(mesg, "\n"); } - err_vcatf(mesg, pre, fn, line, fmt, args); + err_vcatf(mesg, NULL, fn, line, fmt, args); } return exc; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/