ruby-changes:62337
From: aycabta <ko1@a...>
Date: Wed, 22 Jul 2020 02:42:13 +0900 (JST)
Subject: [ruby-changes:62337] 1dfd24a7fc (master): [ruby/irb] Suppress incomplete encoding magic comment error
https://git.ruby-lang.org/ruby.git/commit/?id=1dfd24a7fc From 1dfd24a7fc4e2877d49d2a3326925080e2972cf1 Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Mon, 1 Jun 2020 19:22:50 +0900 Subject: [ruby/irb] Suppress incomplete encoding magic comment error https://github.com/ruby/irb/commit/443e90af80 diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index 5967cdb..02bc548 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -34,8 +34,9 @@ class RubyLex https://github.com/ruby/ruby/blob/trunk/lib/irb/ruby-lex.rb#L34 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 diff --git a/test/irb/test_ruby_lex.rb b/test/irb/test_ruby_lex.rb index 367d1e2..bc5b4fe 100644 --- a/test/irb/test_ruby_lex.rb +++ b/test/irb/test_ruby_lex.rb @@ -139,5 +139,18 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_ruby_lex.rb#L139 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 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/