Skip to content

Fix Dir.glob ../ and cases#8542

Merged
enebo merged 5 commits into
jruby:masterfrom
danini-the-panini:ds-8426-fix-glob
Feb 11, 2025
Merged

Fix Dir.glob ../ and cases#8542
enebo merged 5 commits into
jruby:masterfrom
danini-the-panini:ds-8426-fix-glob

Conversation

@danini-the-panini

@danini-the-panini danini-the-panini commented Dec 21, 2024

Copy link
Copy Markdown
Contributor
  1. Reverts Fix Dir.glob with cases #6681 to resolve Dir[] vs "../../" #8426
  2. Ignore passed-in FNM_CASEFOLD option to Dir.glob, to match MRI.
  3. Modify has_magic to return an enum instead of a boolean.
    This distinguishes paths with "alpha" chars, which get treated as magical in case-insensitive filesystems.
    Forces each path segment to be fetched from the filesystem in order to do a fnmatch, even if it doesn't contain any magic glob patterns.
  4. Maintain SKIPDOT for ALPHA-magic path segments, to ensure FNM_DOTMATCH functionality matches MRI.
  5. Handle schema in glob patterns

@enebo enebo added this to the JRuby 9.4.10.0 milestone Dec 21, 2024
@headius

headius commented Jan 15, 2025

Copy link
Copy Markdown
Member

I am reluctant to revert that fix without some input from @edipofederle on what exactly it fixed. Punting to 9.4.11.0 so we can discuss further.

@danini-the-panini

Copy link
Copy Markdown
Contributor Author

Looking at the logic they added, it just queried the filesystem for the actual path and replaced the glob result with that, taking into account paths starting with ./. However, this does not take into account any .. in the path, which causes massive problems when glob patterns include it. I'm very pro reverting it until a better fix comes around, since I think preserving case in a case-insensitive filesystem is less important than globbing actually working.

The idea wasn't to merely just revert the change, though. I'm also still trying to find a way to do it on the fly, however it's proving to be quite tricky since the glob logic is so convoluted. I may still just try rework the original fix to better take into account .. and . in the glob pattern.

@danini-the-panini danini-the-panini marked this pull request as ready for review January 16, 2025 18:32
@danini-the-panini

Copy link
Copy Markdown
Contributor Author

@headius @enebo how are we feeling about this?

Comment on lines -810 to +831
final int end = begin + path.getRealSize();
final int end = begin + path.length();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i'm not sure if this changes anything. looks like length just returns realSize :/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@danini-the-panini length() is there to satisfy Java CharSequence. It is fine to leave it since it will always match byte length but it is a weird method since it implies it should return char length.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We have discussed in the past modifying the CharSequence methods of ByteList to actually work against the contained characters rather than just the bytes but at this point it's so entrenched we'd have to break the world to do it. I think this is fine.

@enebo enebo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it is impossible to trace through this and know you are prepending scheme in all cases but that is the nature of this code. It is very complicated.

I see no new tests but I do wonder if you noticed any cases which we are lacking coverage?

@danini-the-panini

Copy link
Copy Markdown
Contributor Author

@enebo there aren't really any new test cases, the case I sensitive one was enabled by the previous fix which I reverted. The only other thing to test would be the ../ case but it's quite niche.

@headius headius left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Complicated logic being patched here but I like the changes and the move to an enum for the three-mode magic glob behavior. Minor recommendations to address but otherwise this is good to go.

Comment thread core/src/main/java/org/jruby/util/Dir.java
Comment thread core/src/main/java/org/jruby/util/Dir.java Outdated
Comment on lines -810 to +831
final int end = begin + path.getRealSize();
final int end = begin + path.length();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We have discussed in the past modifying the CharSequence methods of ByteList to actually work against the contained characters rather than just the bytes but at this point it's so entrenched we'd have to break the world to do it. I think this is fine.

Comment thread core/src/main/java/org/jruby/util/Dir.java
@headius

headius commented Jan 28, 2025

Copy link
Copy Markdown
Member

I approve of merging this for 9.4.11.0, or punting to 9.4.12.0.

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.

Dir[] vs "../../"

3 participants