[wp-trac] [WordPress Trac] #45960: plugin_basename() fails on windows path
WordPress Trac
noreply at wordpress.org
Sun Jan 13 13:23:06 UTC 2019
#45960: plugin_basename() fails on windows path
--------------------------+------------------------------
Reporter: dovyp | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: trunk
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Comment (by ayeshrajans):
I use Wordpress on Windows and never faced this problem. There even
appears (https://github.com/WordPress/wordpress-
develop/blob/5.0.1/tests/phpunit/tests/functions/pluginBasename.php#L39)
to be a test with Windows path names.
In any case, instead of a substr()/ltrim(), a simple `preg_replace` should
do a cleaner job.
{{{
preg_replace('|^(?:[A-z]:)|', '', $file);
}}}
Above pattern will behave exactly as your snippet in the issue
description.
{{{
preg_replace('|^(?:[A-z]:)([\\/])|', '$1', $file);
}}}
This pattern will also look for a forward/backwards slash in the file name
(`C:\`), and only remove the `C:` part, making this behave exactly as the
previous regex, but has the additional validation for proceeding slash.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45960#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list