Skip to content
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

Fix readme file issue in Windows #435

Closed
wants to merge 2 commits into from

Conversation

ernilambar
Copy link
Member

@ernilambar ernilambar commented Mar 7, 2024

Fixes #434

@bordoni
Copy link
Member

bordoni commented Mar 12, 2024

@ernilambar can we make sure to add a Changelog here?

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@ernilambar Thank you for the PR!

While this PR addresses the concrete problem you're facing, I wonder whether we should take a step back to find a more holistic solution to the problem.

Paths being different on Windows can affect any checks, and I wonder whether we should cater for that in a more central location, rather than having to adjust any such checks.

WordPress provides a wp_normalize_path() function which takes care of normalizing paths so that they always use /.

Maybe we should use this function in the Abstract_File_Check::get_files() method (and potentially other methods in that class) so that all paths are always normalized? This way we can keep using the common / everywhere, no need for workarounds like this one.

Curious to hear other people's thoughts. cc @swissspidy @mukeshpanchal27

@@ -27,12 +27,15 @@ protected function filter_files_for_readme( array $files, $plugin_relative_path
// Find the readme file.
$readme_list = preg_grep( '/readme\.(txt|md)$/i', $files );

$plugin_relative_path = rtrim( $plugin_relative_path, '/' );
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed? In which situation would $plugin_relative_path end in a forward slash?

// Filter the readme files located at root.
$potential_readme_files = array_filter(
$readme_list,
function ( $file ) use ( $plugin_relative_path ) {
$file = str_replace( $plugin_relative_path, '', $file );
return ! str_contains( $file, '/' );
$file = ltrim( $file, '/\\' );
return ! ( str_contains( $file, '/' ) || str_contains( $file, '\\' ) );
Copy link
Member

Choose a reason for hiding this comment

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

Could be simplified to:

Suggested change
return ! ( str_contains( $file, '/' ) || str_contains( $file, '\\' ) );
return ! str_contains( $file, '/' ) && ! str_contains( $file, '\\' );

@ernilambar
Copy link
Member Author

Closing.

@ernilambar ernilambar closed this Apr 5, 2024
@ernilambar ernilambar deleted the 434-fix-readme-windows branch July 12, 2024 10:47
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.

Windows: Plugin check reports that readme.txt file is missing. Edit Link fails for other files.
3 participants