aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-05-14 22:04:46 -0700
committerJeremy Evans <code@jeremyevans.net>2019-05-22 21:52:20 -0700
commitc05eaa93258ddc01e685b6cc3a0da82998a2af48 (patch)
treeaa5fea51e5d47ed7d49da4b3dfbdb8ce60364ae9 /test
parentf91b1ab33d397fdcdf452d563d7f59469a078d88 (diff)
downloadruby-c05eaa93258ddc01e685b6cc3a0da82998a2af48.tar.gz
Fix mixed encoding in heredoc
Heredocs are parsed line-by-line, so we need to keep track of the temporary encoding of the string. Previously, a heredoc would only detect mixed encoding errors if they were on the same line, this changes things so they will be caught on different lines. Fixes [Bug #15839]
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_syntax.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index c9eaa5af6d..7bf1e0e43c 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -774,6 +774,35 @@ eom
assert_equal("\n0\n1", eval("<<~0 '1'\n \n0\#{}\n0"))
end
+ def test_heredoc_mixed_encoding
+ assert_syntax_error(<<-'HEREDOC', 'UTF-8 mixed within Windows-31J source')
+ #encoding: cp932
+ <<-TEXT
+ \xe9\x9d\u1234
+ TEXT
+ HEREDOC
+ assert_syntax_error(<<-'HEREDOC', 'UTF-8 mixed within Windows-31J source')
+ #encoding: cp932
+ <<-TEXT
+ \xe9\x9d
+ \u1234
+ TEXT
+ HEREDOC
+ assert_syntax_error(<<-'HEREDOC', 'UTF-8 mixed within Windows-31J source')
+ #encoding: cp932
+ <<-TEXT
+ \u1234\xe9\x9d
+ TEXT
+ HEREDOC
+ assert_syntax_error(<<-'HEREDOC', 'UTF-8 mixed within Windows-31J source')
+ #encoding: cp932
+ <<-TEXT
+ \u1234
+ \xe9\x9d
+ TEXT
+ HEREDOC
+ end
+
def test_lineno_operation_brace_block
expected = __LINE__ + 1
actual = caller_lineno\