diff options
author | Takashi Kokubun <[email protected]> | 2022-11-28 20:55:58 -0800 |
---|---|---|
committer | git <[email protected]> | 2022-11-29 04:56:03 +0000 |
commit | 129d208f9a5d54faf2eb4d944bc874fe347bfd64 (patch) | |
tree | cd219d171d0d0dc30d884966c80779b4b1aa28fd | |
parent | b5726892d0d9bf282d54e21e8f170f754c235456 (diff) |
[ruby/erb] Fix line numbers after multi-line <%#
(https://github.com/ruby/erb/pull/42)
https://github.com/ruby/erb/commit/526885923e
-rw-r--r-- | lib/erb/compiler.rb | 2 | ||||
-rw-r--r-- | test/erb/test_erb.rb | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/erb/compiler.rb b/lib/erb/compiler.rb index 835f5be522..547d2c4c44 100644 --- a/lib/erb/compiler.rb +++ b/lib/erb/compiler.rb @@ -384,7 +384,7 @@ class ERB::Compiler # :nodoc: when '<%=' add_insert_cmd(out, content) when '<%#' - # commented out + out.push("\n" * content.count("\n")) # only adjust lineno end end diff --git a/test/erb/test_erb.rb b/test/erb/test_erb.rb index 1db0e55f8a..555345a140 100644 --- a/test/erb/test_erb.rb +++ b/test/erb/test_erb.rb @@ -713,6 +713,18 @@ EOS erb = Marshal.load(Marshal.dump(erb)) assert_raise(ArgumentError) {erb.result} end + + def test_multi_line_comment_lineno + erb = ERB.new(<<~EOS) + <%= __LINE__ %> + <%# + %><%= __LINE__ %> + EOS + assert_equal <<~EOS, erb.result + 1 + 3 + EOS + end end class TestERBCoreWOStrScan < TestERBCore |