Bug #1110
closedencoding warning
Description
=begin
ささだです.
以下のように,-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
=end
Updated by mame (Yusuke Endoh) about 16 years ago
=begin
遠藤です。
2009/2/5 SASADA Koichi [email protected]:
ささだです.
以下のように,-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 [email protected]
=end
Updated by duerst (Martin Dürst) about 16 years ago
=begin
begin/end で直すのに一票。そういう手があったのには気がつかなかったです。
よろしくお願いします。 Martin.
On 2009/04/01 21:27, Yusuke ENDOH wrote:
遠藤です。
2009/2/5 SASADA Koichi[email protected]:
ささだです.
以下のように,-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;
}
--
#-# Martin J.Dürst, Professor, Aoyama Gakuin University
#-# http://www.sw.it.aoyama.ac.jp mailto:[email protected]
=end
Updated by yugui (Yuki Sonoda) almost 16 years ago
- Status changed from Open to Closed
- ruby -v set to 知らん
=begin
applied in an ancient changeset.
=end