Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Avoid throwing a notice about `strpos(): Empty needle` when going through include paths #149
Conversation
@@ -176,7 +176,7 @@ protected static function containsMatchingChildren( SplFileInfo $dir, array $mat | |||
// Or the start of the matcher until the first wildcard matches the start of the path. | |||
if ( | |||
( '' !== $root_relative_path && 0 === strpos( $base, $root_relative_path ) ) || | |||
0 === strpos( $root_relative_path, $base ) | |||
( '' !== $base && 0 === strpos( $root_relative_path, $base ) ) |
schlessera
Mar 23, 2019
Member
@swissspidy This now saves against the thrown notice, but I'm wondering whether it doesn't now exclude valid matches.
If $base
is empty, should a match be possible here?
@swissspidy This now saves against the thrown notice, but I'm wondering whether it doesn't now exclude valid matches.
If $base
is empty, should a match be possible here?
connerbw
Mar 24, 2019
•
Author
Contributor
The old code, without my change, in context, was:
if (
( '' !== $root_relative_path && 0 === strpos( $base, $root_relative_path ) ) ||
0 === strpos( $root_relative_path, $base )
) {
return true;
}
}
return false;
Written another way:
if (
$CONDITION_1 ||
$CONDITION_2
) {
return true;
}
}
return false;
My change only suppresses the warning:
$CONDITION_2 = strpos( 'node_modules', '' );
var_dump($CONDITION_2);
// false, aka:
$CONDITION_2 = 0 === strpos( 'node_modules', '' );
var_dump($CONDITION_2);
// false
$CONDITION_2 = '' !== '' ;
var_dump($CONDITION_2);
// false
whether it doesn't now exclude valid matches. If $base is empty, should a match be possible here?
My change doesn't change how the code works, it only suppresses the PHP Warning.
If a match is possible, and the testing suite doesn't catch it, then that's beyond the scope of my PR IMHO.
Hope this helps.
The old code, without my change, in context, was:
if (
( '' !== $root_relative_path && 0 === strpos( $base, $root_relative_path ) ) ||
0 === strpos( $root_relative_path, $base )
) {
return true;
}
}
return false;
Written another way:
if (
$CONDITION_1 ||
$CONDITION_2
) {
return true;
}
}
return false;
My change only suppresses the warning:
$CONDITION_2 = strpos( 'node_modules', '' );
var_dump($CONDITION_2);
// false, aka:
$CONDITION_2 = 0 === strpos( 'node_modules', '' );
var_dump($CONDITION_2);
// false
$CONDITION_2 = '' !== '' ;
var_dump($CONDITION_2);
// false
whether it doesn't now exclude valid matches. If $base is empty, should a match be possible here?
My change doesn't change how the code works, it only suppresses the PHP Warning.
If a match is possible, and the testing suite doesn't catch it, then that's beyond the scope of my PR IMHO.
Hope this helps.
schlessera
Apr 1, 2019
•
Member
Yes, it was clear how the logic works. However, the PR should ideally be about eliminating the root cause of a bug, not just obfuscating it.
In this case, the root cause is that one possible scenario was apparently not being considered by the current logic. The notice as such is valuable as it shows us we apparently forgot something. If we now just hide the notice, the possible bug might still be in there and forgotten because the symptom is being hidden.
This is why I'd like some feedback by @swissspidy, who built the original code, as I'm unsure what an empty base in this case would signify.
Yes, it was clear how the logic works. However, the PR should ideally be about eliminating the root cause of a bug, not just obfuscating it.
In this case, the root cause is that one possible scenario was apparently not being considered by the current logic. The notice as such is valuable as it shows us we apparently forgot something. If we now just hide the notice, the possible bug might still be in there and forgotten because the symptom is being hidden.
This is why I'd like some feedback by @swissspidy, who built the original code, as I'm unsure what an empty base in this case would signify.
swissspidy
Apr 1, 2019
Member
Hmm I think my initial work was pretty much rewritten in #104. So maybe @herregroen knows more?
The warning implies that $path_or_file
is an empty string and I wonder why this happens. If it's because of some edge case thing I don't think just break
ing early would cause any troubles.
Hmm I think my initial work was pretty much rewritten in #104. So maybe @herregroen knows more?
The warning implies that $path_or_file
is an empty string and I wonder why this happens. If it's because of some edge case thing I don't think just break
ing early would cause any troubles.
connerbw
Apr 1, 2019
Author
Contributor
Maybe this helps? I can reproduce every time by running:
wp i18n make-pot . languages/plugin.pot --include="*.blade.php" --exclude="vendor,symbionts" --headers='{"Report-Msgid-Bugs-To":"https://github.com/namespace/plugin/"}
Maybe this helps? I can reproduce every time by running:
wp i18n make-pot . languages/plugin.pot --include="*.blade.php" --exclude="vendor,symbionts" --headers='{"Report-Msgid-Bugs-To":"https://github.com/namespace/plugin/"}
schlessera
Aug 6, 2019
Member
@swissspidy I think you misread the code. The issue is not that $path_or_file
is empty, but that current( explode( '*', $path_or_file ) )
returns an empty string. This happens for a simple example like *.php
, as it will explode to [ '', '.php' ]
.
@swissspidy I think you misread the code. The issue is not that $path_or_file
is empty, but that current( explode( '*', $path_or_file ) )
returns an empty string. This happens for a simple example like *.php
, as it will explode to [ '', '.php' ]
.
swissspidy
Aug 6, 2019
Member
Ah, indeed! My bad.
Ah, indeed! My bad.
I'm not so sure that the logic is actually sound, as we seem to just be hiding the problem with this PR. Nevertheless, it gets rid of the notice, and it doesn't actually break anything that wouldn't already be broken in that case anyway. So I'll go ahead and merge this for now. |
502185d
into
wp-cli:master
I'm still getting a warning about "empty needles" when running |
@markhowellsmead Could you please create a new issue for that so we can track this? Thanks! |
connerbw commentedMar 22, 2019
Kept getting this warning when doing
--include="*.blade.php"
, among other things.Related to #125 and #129