Skip to content

FIX Allow 0 as a directory name#683

Merged
emteknetnz merged 1 commit intosilverstripe:3.0from
creative-commoners:pulls/3.0/zero-dir
Apr 29, 2025
Merged

FIX Allow 0 as a directory name#683
emteknetnz merged 1 commit intosilverstripe:3.0from
creative-commoners:pulls/3.0/zero-dir

Conversation

@GuySartorelli
Copy link
Copy Markdown
Member

This isn't Path::join() but the same problem applies as described in the issue - "0" is being filtered out even though it's valid.

Issue

Comment thread src/File.php
protected static function getFilePathParts(string $filePath): array
{
// Explicitly allow zero as a segment in the path (e.g. /some/path/0/file.txt)
$notEmpty = fn(mixed $part) => ($part === 0 || $part === '0' || (bool) $part);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess the conversion is implicit here, is it not? Ok to leave as is if it's better from some perspective.

Suggested change
$notEmpty = fn(mixed $part) => ($part === 0 || $part === '0' || (bool) $part);
$notEmpty = fn(mixed $part) => ($part === 0 || $part === '0' || $part);

Copy link
Copy Markdown
Member Author

@GuySartorelli GuySartorelli Apr 28, 2025

Choose a reason for hiding this comment

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

Yeah, I guess it is implicitly cast if not done explicitly. In my head it made sense to be explicit here but both do exactly the same thing. I think this is just up to subjective preference.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I learnt not to cast to bool if it's in any logical condition/expression as PhpStorm always hints at it as useless due to it being casted implicitly.

@michalkleiner
Copy link
Copy Markdown
Contributor

michalkleiner commented Apr 28, 2025

Is there a test case we can add or adjust to see the new/fixed behaviour?
The tests are part of the framework change, so all good.

Comment thread src/File.php
@emteknetnz emteknetnz merged commit 8e35c43 into silverstripe:3.0 Apr 29, 2025
8 checks passed
@emteknetnz emteknetnz deleted the pulls/3.0/zero-dir branch April 29, 2025 01:50
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.

3 participants