aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-12 03:50:33 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-08-12 03:50:33 +0000
commit08dbb0f942a66180c0e0cdd7219659e4c3bfc1da (patch)
tree555cb78d1be89ad3464928d5e021c1f6e8c85b7e
parent9e909c3e8440a78cbfe4da06492af0bb2c0cca75 (diff)
downloadruby-08dbb0f942a66180c0e0cdd7219659e4c3bfc1da.tar.gz
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55878 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--error.c6
-rw-r--r--test/ruby/test_iseq.rb3
3 files changed, 12 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index bcbeca0987..f806c2791d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Fri Aug 12 12:50:31 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@nerdinand.com>
* compar.c (cmp_clamp): Introduce Comparable#clamp. [Feature #10594]
diff --git a/error.c b/error.c
index 27ca7db8d2..bb10e295af 100644
--- a/error.c
+++ b/error.c
@@ -106,16 +106,16 @@ rb_syntax_error_append(VALUE exc, VALUE file, int line, int column,
}
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;
diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb
index dba714aa62..cdfa380edd 100644
--- a/test/ruby/test_iseq.rb
+++ b/test/ruby/test_iseq.rb
@@ -234,6 +234,9 @@ class TestISeq < Test::Unit::TestCase
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