[BUG:1.9] Dir.glob should not convert entries on UNIX


#1

e$B$3$s$P$s$Oe(B sheepman e$B$G$9!#e(B

File.open e$B$NF0:n$H@09g@-$r;}$?$;$k$?$a$K!"e(BDir.glob e$B$Oe(B UNIX
e$B>e$G$O!"e(B
e$BM?$($i$l$?J8;zNs$H%U%!%$%k%7%9%F%`$+$iF@$i$l$?J8;zNs$r!"JQ49$;$:e(B
e$B$=$N$^$^%P%$%HNs$H$7$FHf3S$9$k$Y$-$@$H;W$$$^$9!#e(B

e$B0J2<$N$h$&$K%G%#%l%/%H%j$KB8:_$9$k%U%!%$%k$NL>A0$,e(B
Shift_JISe$B$G$"$k>l9g$KNc30$,H/@8$7$^$9!#e(B

$ uname -sr
Linux 2.6.16-76.39vl4

$ cat t.rb

encoding:euc-jp

Dir.glob(‘e$B%F%9%He(B*’)

$ ls | nkf --guess
Shift_JIS

$ ruby-1.9 -v t.rb
ruby 1.9.2dev (2009-04-04 trunk 23134) [i686-linux]
t.rb:2:in glob': invalid byte sequence in EUC-JP (ArgumentError) from t.rb:2:in

e$B$5$i$K2<$N$h$&$JNc$G$bNc30$,H/@8$7$^$9!#e(B

$ cat t.rb

encoding:euc-jp

Dir.glob(‘test*’)

$ ls | nkf --guess
Shift_JIS

$ ruby-1.9 -v t.rb
ruby 1.9.2dev (2009-04-04 trunk 23134) [i686-linux]
t.rb:2:in glob': invalid byte sequence in EUC-JP (ArgumentError) from t.rb:2:in

e$B$5$i$K$5$i$Ke(B -Ebinary e$B$rM?$($F$bNc30$,H/@8$7$^$9!#e(B

$ cat t.rb

encoding:euc-jp

Dir.glob(‘test*’)

$ ls | nkf --guess
Shift_JIS

$ ruby-1.9 -Ebinary -v t.rb
ruby 1.9.2dev (2009-04-04 trunk 23134) [i686-linux]
t.rb:2:in glob': invalid byte sequence in EUC-JP (ArgumentError) from t.rb:2:in


#2

ujihisae$B$H$$$$$^$9!#e(B

r23171
e$B$+$i!"e(Bbrackete$B$r4^$`e(BDir.globe$B$,$&$^$/F0$$$F$$$^$;$s$G$7$?!#e(B
$ ./ruby -e “p Dir.glob(’/[ae]tc/’)”
[]

e$B0J2<$O%Q%C%A$G$9!#$3$l$rEv$F$k$H!"e(B mspec
./spec/rubyspec/core/dir/glob_spec.rb e$B$KDL$k$h$&$K$J$j$^$9!#e(B

diff --git a/dir.c b/dir.c
index 14b4872…dab55f7 100644
— a/dir.c
+++ b/dir.c
@@ -136,9 +136,12 @@ bracket(
else {
if (ok) continue;
if (r <= (send-s) && memcmp(p, s, r) == 0) continue;

  •  if (!nocase) continue;
    
  •  c1 = rb_enc_toupper(rb_enc_codepoint(s, send, enc), enc);
    
  •  c2 = rb_enc_toupper(rb_enc_codepoint(p, pend, enc), enc);
    
  •  c1 = rb_enc_codepoint(t1, t1 + strlen(t1), enc);
    
  •  c2 = rb_enc_codepoint(s, send, enc);
    
  •  if (nocase) {
    
  • c1 = rb_enc_toupper(c1, enc);
  • c2 = rb_enc_toupper(c2, enc);
  •  }
     if (c1 != c2) continue;
    
    }
    ok = 1;

#3

e$B%A%1%C%He(B #1378 e$B$,99?7$5$l$^$7$?!#e(B (by Nobuyoshi N.)

e$B%9%F!<%?%9e(B Opene$B$+$ie(BClosede$B$KJQ99e(B
e$B?JD=e(B % 0e$B$+$ie(B100e$B$KJQ99e(B

Applied in changeset r23189.

http://redmine.ruby-lang.org/issues/show/1378


#4

e$B$3$s$P$s$Oe(B sheepman e$B$G$9!#e(B

r23189 e$B$NE,MQ8e$G$b0J2<$N$h$&$Ke(B Shift_JIS
e$B$N%U%!%$%kL>$,$"$k>l9g$Ke(B
e$BNc30$,H/@8$7$^$9$,!"$3$l$O$3$&$$$&$b$N$G$7$g$&$+!#e(BDir.glob
e$B$NL\E*$+$ie(B
e$B8@$C$F!“JQ49$K<:GT$7$?>l9g$ONc30$rH/@8$5$;$:!”%9%-%C%W$9$k$Y$-$J$N$G$Oe(B
e$B$J$$$G$7$g$&$+!#e(BDir.entries e$B$be(B UNIX e$B>e$G$Oe(B locale
e$B$KBP$7$FIT@5$J%U%!%$%kL>$,e(B
e$B$"$C$F$bNc30$rH/@8$5$;$J$$$o$1$G$9$7!#e(B

$ echo $LANG
ja_JP.eucJP

$ cat t.rb

encoding:euc-jp

p Dir.glob(’[e$B%Fe(B-e$B%He(B]’)

$ ls | nkf --guess
Shift_JIS

$ ruby-1.9 -v t.rb
ruby 1.9.2dev (2009-04-14 trunk 23189) [i686-linux]
t.rb:2:in glob': invalid byte sequence in EUC-JP (ArgumentError) from t.rb:2:in


#5

e$B%A%1%C%He(B #1379 e$B$,99?7$5$l$^$7$?!#e(B (by Yui NARUSE)

e$B%9%F!<%?%9e(B Opene$B$+$ie(BClosede$B$KJQ99e(B
e$B?JD=e(B % 0e$B$+$ie(B100e$B$KJQ99e(B

Applied in changeset r23190.

http://redmine.ruby-lang.org/issues/show/1379