diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2024-05-08 19:25:37 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2024-05-08 19:25:37 +0900 |
commit | 5bb656e4f063e717262efe2dc303ed914eb1dd6c (patch) | |
tree | adeabf59d5c38be6dca435bf5e8b8ff17dc2b924 | |
parent | 841b45a4421a7f103b0312f84c14ece522833617 (diff) |
[Bug #20474] Keep spaces in leading blank line
-rw-r--r-- | parse.y | 4 | ||||
-rw-r--r-- | test/ruby/test_syntax.rb | 12 |
2 files changed, 15 insertions, 1 deletions
@@ -8578,6 +8578,10 @@ parser_update_heredoc_indent(struct parser_params *p, int c) } p->heredoc_line_indent = -1; } + else { + /* Whitespace only line has no indentation */ + p->heredoc_line_indent = 0; + } } return FALSE; } diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 8bdac2ebd1..7b894eee79 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -889,6 +889,16 @@ e" assert_dedented_heredoc(expect, result) end + def test_dedented_heredoc_with_leading_blank_line + # the blank line has six leading spaces + result = " \n" \ + " b\n" + expect = " \n" \ + "b\n" + assert_dedented_heredoc(expect, result) + end + + def test_dedented_heredoc_with_blank_more_indented_line_escaped result = " a\n" \ "\\ \\ \\ \\ \\ \\ \n" \ @@ -996,7 +1006,7 @@ eom end def test_dedented_heredoc_concatenation - assert_equal("\n0\n1", eval("<<~0 '1'\n \n0\#{}\n0")) + assert_equal(" \n0\n1", eval("<<~0 '1'\n \n0\#{}\n0")) end def test_heredoc_mixed_encoding |