mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/irb] Suppress incomplete encoding magic comment error
https://github.com/ruby/irb/commit/443e90af80
This commit is contained in:
parent
78ccab2530
commit
1dfd24a7fc
2 changed files with 16 additions and 2 deletions
|
@ -34,8 +34,9 @@ class RubyLex
|
|||
begin
|
||||
result = yield code
|
||||
rescue ArgumentError => e
|
||||
if e.message.match?(/unknown encoding name/) && code.match?(/\A(?<shebang>#.*\n)?#\s*coding\s*:.*(?<nl>\n)?/)
|
||||
code = code.gsub(/\A(?<shebang>#.*\n)?#\s*coding\s*:.*(?<nl>\n)?/, "\\k<shebang>#\\k<nl>")
|
||||
magic_comment_regexp = /\A(?<shebang>#.*\n)?#\s*(?:encoding|coding)\s*:.*(?<nl>\n)?/
|
||||
if e.message.match?(/unknown encoding name/) && code.match?(magic_comment_regexp)
|
||||
code = code.gsub(magic_comment_regexp, "\\k<shebang>#\\k<nl>")
|
||||
retry
|
||||
end
|
||||
end
|
||||
|
|
|
@ -139,5 +139,18 @@ module TestIRB
|
|||
assert_indenting(lines, row.new_line_spaces, true)
|
||||
end
|
||||
end
|
||||
|
||||
def test_incomplete_encoding_magic_comment
|
||||
input_with_correct_indents = [
|
||||
Row.new(%q(#encoding:u), nil, 0),
|
||||
]
|
||||
|
||||
lines = []
|
||||
input_with_correct_indents.each do |row|
|
||||
lines << row.content
|
||||
assert_indenting(lines, row.current_line_spaces, false)
|
||||
assert_indenting(lines, row.new_line_spaces, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue