-
Notifications
You must be signed in to change notification settings - Fork 576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Protect from undef values in Mojo::File objects #1393
Conversation
I'm not 100% sure if it is worth the performance cost, but i'm giving it a 👍 personally and call for a vote anyway @mojolicious/core. |
If I had voting rights I'd be 👍 for this. I've fallen into this trap myself. |
Im 👍 Sent with GitHawk |
👍 |
lib/Mojo/File.pm
Outdated
@@ -24,7 +24,7 @@ our @EXPORT_OK = ('path', 'tempdir', 'tempfile'); | |||
|
|||
sub basename { File::Basename::basename ${shift()}, @_ } | |||
|
|||
sub child { $_[0]->new(@_) } | |||
sub child { $_[0]->new(${shift()}, @_) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've already voted in favor but can you explain the significance of this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally insignificant. It's an optimization that's already in master actually. 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes ->child
calls a lot faster though since it avoids stringification later.
…hare', undef)->remove_tree")
It is currently very easy to delete the wrong directory by accident, like:
This would currently delete
usr/share
and only show a pretty insignificant warning about theundef
value. I noticed the problem because we had a similar accident at work. 😉The performance cost is pretty minimal. I would have liked to include the empty string too, but unfortunately we depend on that currently for a Mojo::Home hack that i don't dare to change again.