From: Yusuke ENDOH Date: 2009-04-01T21:27:51+09:00 Subject: [ruby-dev:38240] Re: [BUG: 1.9] encoding warning 遠藤です。 2009/2/5 SASADA Koichi : >  ささだです. > > 以下のように,-v や -w 付きの ruby で erb を require すると,"coding: > ..." の場所が違うよ,という警告が出ます. > > $ cat test.rb > require 'erb' > > $ /tmp/trunk/bin/ruby -v test.rb > ruby 1.9.2dev (2009-02-05 trunk 22076) [x86_64-linux] > test.rb:1: warning: encoding 'UTF-8' is ignored, valid only in the first > line except for shebang line. > test.rb:1: warning: encoding 'Big5' is ignored, valid only in the first > line except for shebang line. > > これは,2つの問題があるかと思います. > > (1) erb の説明のコメントに反応して警告をしている > > ちょっと見てみると,68 行目にコメント中のサンプルコードとして > > # # -*- coding: UTF-8 -*- > > という行が,72 行目に > > # <%#-*- coding: Big5 -*-%> > > という行があります.これに対しての警告じゃないかと思います.ちょっとやり > すぎ? > > > (2) require している行の警告として出ている > > test.rb:1: warning: encoding 'UTF-8' is ignored, valid only in the first > line except for shebang line. > > と,require している行が警告行として表示されています.多分,erb.rb:68 と > かと表示してくれたほうがいいと思います. > > > > (1) はどうかな,と思います.(2) は,直したほうがいいんではないかと思い > ます. > > # (1) の ad-hoc な解決策として,=begin/=end で囲ってしまうってのが > # あるようです. > > -- > // SASADA Koichi at atdot dot net この件、どうなるものでしょう。hoe で実際に発症しています。 $ sow19 /home/mame/work/ruby19/local/lib/ruby/gems/1.9.1/gems/hoe-1.12.1/bin/sow:10: warning: encoding 'UTF-8' is ignored, valid only in the first line except for shebang line. /home/mame/work/ruby19/local/lib/ruby/gems/1.9.1/gems/hoe-1.12.1/bin/sow:10: warning: encoding 'Big5' is ignored, valid only in the first line except for shebang line. usage: sow19 [-d|-t] project -t = add project to subdir under 'trunk' -d = add project to subdir under 'dev' 実害はないものの、なかなかめざわりです。 とりあえずパッチです。 Index: lib/erb.rb =================================================================== --- lib/erb.rb (revision 23115) +++ lib/erb.rb (working copy) @@ -65,6 +65,7 @@ # a magic comment, however, it returns a string in the encoding specified # by the magic comment. # +=begin # # -*- coding: UTF-8 -*- # require 'erb' # @@ -73,6 +74,7 @@ # \_\_ENCODING\_\_ is <%= \_\_ENCODING\_\_ %>. # EOF # puts template.result +=end # # Prints: \_\_ENCODING\_\_ is Big5. # Index: parse.y =================================================================== --- parse.y (revision 23115) +++ parse.y (working copy) @@ -6089,7 +6089,7 @@ magic_comment_encoding(struct parser_params *parser, const char *name, const char *val) { if (!comment_at_top(parser)) { - rb_warning("encoding '%s' is ignored, valid only in the first line except for shebang line.", + rb_warningS("encoding '%s' is ignored, valid only in the first line except for shebang line.", val); return; } -- Yusuke ENDOH