summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-02-11 11:04:41 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-02-11 11:04:41 +0000
commit76ee1d849414321047fed683b81583bc2ab14d4c (patch)
tree6b12d5ca96284ab1cd3ff4b2da6480972047060e
parent9b80483fc832267ed733b1e239d5be1869414b08 (diff)
merge revision(s) 62872,62873: [Backport #14621]
parse.y: unindent continued line * parse.y (tokadd_string): stop at continued line in dedented here documents, to dedent for each lines before removing escaped newlines. [ruby-core:86236] [Bug #14621] parse.y: terminator at continued line * parse.y (here_document): a continuing line is not the terminator. [ruby-core:86283] [Bug #14621] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@67050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--parse.y19
-rw-r--r--test/ruby/test_syntax.rb18
-rw-r--r--version.h6
3 files changed, 38 insertions, 5 deletions
diff --git a/parse.y b/parse.y
index 1348842b91..3b3bd7a4ca 100644
--- a/parse.y
+++ b/parse.y
@@ -6394,7 +6394,14 @@ parser_tokadd_string(struct parser_params *parser,
switch (c) {
case '\n':
if (func & STR_FUNC_QWORDS) break;
- if (func & STR_FUNC_EXPAND) continue;
+ if (func & STR_FUNC_EXPAND) {
+ if (!(func & STR_FUNC_INDENT) || (heredoc_indent < 0))
+ continue;
+ if (c == term) {
+ c = '\\';
+ goto terminate;
+ }
+ }
tokadd('\\');
break;
@@ -6475,6 +6482,7 @@ parser_tokadd_string(struct parser_params *parser,
}
tokadd(c);
}
+ terminate:
if (enc) *encp = enc;
return c;
}
@@ -7019,7 +7027,13 @@ parser_here_document(struct parser_params *parser, rb_strterm_heredoc_t *here)
return 0;
}
bol = was_bol();
- if (bol && whole_match_p(eos, len, indent)) {
+ /* `heredoc_line_indent == -1` means
+ * - "after an interpolation in the same line", or
+ * - "in a continuing line"
+ */
+ if (bol &&
+ (heredoc_line_indent != -1 || (heredoc_line_indent = 0)) &&
+ whole_match_p(eos, len, indent)) {
dispatch_heredoc_end();
heredoc_restore(&lex_strterm->u.heredoc);
lex_strterm = 0;
@@ -7090,6 +7104,7 @@ parser_here_document(struct parser_params *parser, rb_strterm_heredoc_t *here)
goto restore;
}
if (c != '\n') {
+ if (c == '\\') heredoc_line_indent = -1;
flush:
str = STR_NEW3(tok(), toklen(), enc, func);
flush_str:
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index 7e25d965df..b81ec9096d 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -678,6 +678,24 @@ e"
assert_dedented_heredoc(expected, result)
end
+ def test_dedented_heredoc_continued_line
+ result = " 1\\\n" " 2\n"
+ expected = "1\\\n" "2\n"
+ assert_dedented_heredoc(expected, result)
+ assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /can't find string "TEXT"/)
+ begin;
+ <<-TEXT
+ \
+ TEXT
+ end;
+ assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /can't find string "TEXT"/)
+ begin;
+ <<~TEXT
+ \
+ TEXT
+ end;
+ end
+
def test_lineno_after_heredoc
bug7559 = '[ruby-dev:46737]'
expected, _, actual = __LINE__, <<eom, __LINE__
diff --git a/version.h b/version.h
index 60fef81371..552c7a72b8 100644
--- a/version.h
+++ b/version.h
@@ -1,10 +1,10 @@
#define RUBY_VERSION "2.5.4"
-#define RUBY_RELEASE_DATE "2019-02-05"
-#define RUBY_PATCHLEVEL 139
+#define RUBY_RELEASE_DATE "2019-02-11"
+#define RUBY_PATCHLEVEL 140
#define RUBY_RELEASE_YEAR 2019
#define RUBY_RELEASE_MONTH 2
-#define RUBY_RELEASE_DAY 5
+#define RUBY_RELEASE_DAY 11
#include "ruby/version.h"