Skip to content

Conversation

@danini-the-panini
Copy link
Contributor

Resolve #8623

Copy link
Member

@enebo enebo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should be using the String construction listed above in my comment for your createResource line. I think links.size() > 0 section also uses the same call and it should also be changed.

I am going to ask @headius on channel to review this since glob is always too complicated.

buf.append( isRoot(base) ? EMPTY : SLASH );
buf.append( getBytesInUTF8(file) );
if ( SLASH_INDEX == -1 ) {
resource = JRubyFile.createResource(runtime, cwd, RubyString.byteListToString(buf));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up above we see the same resource creation but it uses the encoding for charset:

resource = JRubyFile.createResource(runtime, cwd, new String(buf.unsafeBytes(), buf.begin(), buf.length(), enc.getCharset()));

This enc comes from the original pattern and that pattern is fed through RubyFile#get_path/filePathConvert which has special logic for transcoding if NOT on windows to match filesystem encoding. I think the use of byteListToString (used both here and below) is wrong. It will make an ISO-8859-1 string where each byte is a char vs the line above which properly decodes the bytes given with the charset provided.

I think the reason we do not ever see problems is almost all files are single-byte ASCII.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think this risks losing encoding and possibly dealing with mangled characters. If we cannot fix it by working with the possibly-multibyte characters directly, then we should use the functions in RubyEncoding to decode them to String properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorted

Comment on lines 996 to 1008
resource = JRubyFile.createResource(runtime, cwd, RubyString.byteListToString(link));
if ( resource.isDirectory() ) {
final int len = link.getRealSize();
buf.length(0);
buf.append(link);
buf.append(path, SLASH_INDEX, end - SLASH_INDEX);
status = glob_helper(runtime, cwd, scheme, buf, buf.getBegin() + len, flags, func, arg);
}
final int len = link.getRealSize();
buf.length(0);
buf.append(link);
buf.append(path, SLASH_INDEX, end - SLASH_INDEX);
status = glob_helper(runtime, cwd, scheme, buf, buf.getBegin() + len, flags, func, arg);
Copy link
Contributor Author

@danini-the-panini danini-the-panini Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so i moved the isDirectory check to where we append to links rather than the loop. This might cause an issue where links would have contained only non-directories, it should still call break mainLoop, although I haven't seen any issues. I don't know how I would cause this to happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reverted this change

@enebo enebo added this to the JRuby 9.4.13.0 milestone Feb 25, 2025
@enebo enebo merged commit bc239fe into jruby:master Feb 25, 2025
94 of 95 checks passed
@danini-the-panini danini-the-panini deleted the ds-fix-dir-glob-windows branch February 25, 2025 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Installing sassc broke on jruby-head on Windows

3 participants