@@ -973,11 +973,22 @@ private static int glob_helper(Ruby runtime, String cwd, byte[] scheme,
973973 }
974974 if ( fnmatch (magic , 0 , magic .length , fileBytes , 0 , fileBytes .length , flags ) == 0 ) {
975975 buf .length (0 );
976- if (scheme != null && SLASH_INDEX == -1 ) buf .append (scheme );
977976 buf .append (base );
978977 buf .append ( isRoot (base ) ? EMPTY : SLASH );
979978 buf .append ( getBytesInUTF8 (file ) );
980- if ( SLASH_INDEX == -1 ) {
979+ boolean dirMatch = false ;
980+ if (SLASH_INDEX == end - 1 ) {
981+ resource = JRubyFile .createResource (runtime , cwd , new String (buf .unsafeBytes (), buf .begin (), buf .length (), enc .getCharset ()));
982+ dirMatch = resource .isDirectory ();
983+ }
984+ if ( dirMatch || SLASH_INDEX == -1 ) {
985+ if (scheme != null ) {
986+ byte [] bufBytes = buf .bytes ();
987+ buf .length (0 );
988+ buf .append (scheme );
989+ buf .append (bufBytes );
990+ }
991+ if (dirMatch ) buf .append (SLASH );
981992 status = func .call (buf .getUnsafeBytes (), 0 , buf .getRealSize (), enc , arg );
982993 if ( status != 0 ) break ;
983994 continue ;
@@ -993,7 +1004,7 @@ private static int glob_helper(Ruby runtime, String cwd, byte[] scheme,
9931004 for ( DirGlobber globber : links ) {
9941005 final ByteList link = globber .link ;
9951006 if ( status == 0 ) {
996- resource = JRubyFile .createResource (runtime , cwd , RubyString . byteListToString ( link ));
1007+ resource = JRubyFile .createResource (runtime , cwd , new String ( link . unsafeBytes (), link . begin (), link . length (), enc . getCharset () ));
9971008 if ( resource .isDirectory () ) {
9981009 final int len = link .getRealSize ();
9991010 buf .length (0 );
0 commit comments