Skip to content

Introducing \WP_CLI\Utils\normalize_path function. Using it for ABSPATH constant.#4718

Merged
schlessera merged 4 commits intowp-cli:masterfrom
ericgopak:master
Mar 18, 2018
Merged

Introducing \WP_CLI\Utils\normalize_path function. Using it for ABSPATH constant.#4718
schlessera merged 4 commits intowp-cli:masterfrom
ericgopak:master

Conversation

@ericgopak
Copy link
Copy Markdown
Contributor

As discussed with @gitlost here: wp-cli/checksum-command#39
Introducing normalize_path function (copied it from latest the WP Core :) ), and applied it to the ABSPATH constant, so that path concatenations of it have (more or less) consistent path separators.

@ericgopak
Copy link
Copy Markdown
Contributor Author

I didn't modify any other functions (like e.g. Utils\get_temp_dir) to make use of this path normalization, since I am not sure it won't break anything for Windows users.

I think it's great that we now have this normalization function, since everyone can now use it for cross-platform (in other words, Windows-friendly) path operations.

Copy link
Copy Markdown
Member

@schlessera schlessera left a comment

Choose a reason for hiding this comment

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

Only minor nitpicking.

php/utils.php Outdated
/**
* Normalize a filesystem path.
*
* On windows systems, replaces backslashes with forward slashes
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.

windows => Windows

php/utils.php Outdated
* On windows systems, replaces backslashes with forward slashes
* and forces upper-case drive letters.
* Allows for two leading slashes for Windows network shares, but
* ensures that all other duplicate slashes are reduced to a single.
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.

reduced to a single. => reduced to a single one.

@gitlost
Copy link
Copy Markdown
Contributor

gitlost commented Mar 5, 2018

copied it from latest the WP Core

Ah cool, somehow I wasn't aware of this function wp_normalize_path(). There's a trunk version that deals with PHP stream wrappers changeset [42387] but we can ignore that for now I think.

If you could copy the core test also, to tests/test-utils.php, it'd be good.

I didn't modify any other functions

That's fine, will be done in another PR.

I think it's great that we now have this normalization function

Absolutely!

php/utils.php Outdated
* Allows for two leading slashes for Windows network shares, but
* ensures that all other duplicate slashes are reduced to a single.
* Ensures upper-case drive letters on Windows systems.
* Allows for Windows network shares.
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.

To add my nitpicks, can just remove this comment "Allows for WIndows network shares." (taken from the since I see) as it's covered above. Also maybe add Copied from core wp_normalize_path(). or similar, and access public and category System tags as in for instance trailingslashit().

@ericgopak
Copy link
Copy Markdown
Contributor Author

Thanks a lot @schlessera and @gitlost for the feedback. I'm very happy to see the high bar for the code quality :)

I've addressed all of your feedback above, please review!

I've also added a unit test for the new function, where I copied all of the WP Core test cases plus added a couple of new ones (like empty-string test and root-only test).

There's a trunk version that deals with PHP stream wrappers changeset [42387] but we can ignore that for now I think.

Yes, I agree, no need to worry about it for now, but in general I like the idea of having a wrapper for paths - if done well, that would alleviate quite a bit of potential path-related headache :)

Copy link
Copy Markdown
Contributor

@gitlost gitlost left a comment

Choose a reason for hiding this comment

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

Good stuff @ericgopak , thanks!

@gitlost
Copy link
Copy Markdown
Contributor

gitlost commented Mar 6, 2018

Just to note the Travis failure for the trunk job is due to this recent change https://core.trac.wordpress.org/ticket/43228

@ericgopak
Copy link
Copy Markdown
Contributor Author

Thanks @gitlost for the note!

Then we're just waiting for @schlessera to approve this PR.

@gitlost
Copy link
Copy Markdown
Contributor

gitlost commented Mar 6, 2018

@ericgopak Just to note we also have to wait for the trunk issue to be resolved (or if that takes too long workaround it - which is easy to do but better if we don't).

@schlessera schlessera merged commit 30e55f6 into wp-cli:master Mar 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants