Skip to content

Commit

Permalink
Merge pull request #224 from alleyinteractive/fix/validate-file-windows
Browse files Browse the repository at this point in the history
Add support for Windows filepaths
  • Loading branch information
kevinfodness authored Dec 18, 2023
2 parents 35e6eb0 + bfe7785 commit 6fde834
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion byline-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Author URI: https://alley.com
* Text Domain: byline-manager
* Domain Path: /languages
* Version: 0.2.3
* Version: 0.2.4
* Requires WP: 5.9
* Requires PHP: 8.0
* Tested up to: 6.3
Expand All @@ -24,6 +24,17 @@

define( 'BYLINE_MANAGER_PATH', __DIR__ . '/' );

/**
* Helper function to validate a path before doing something with it.
*
* @param string $path The path to validate.
*
* @return bool True if the path is valid, false otherwise.
*/
function validate_path( string $path ) : bool {
return in_array( validate_file( $path ), [ 0, 2 ], true ) && file_exists( $path );
}

// Autoloader.
require_once BYLINE_MANAGER_PATH . 'inc/autoload.php';

Expand Down
4 changes: 2 additions & 2 deletions inc/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function get_asset_dependencies( string $asset ) : array {
}

// Ensure the filepath is valid.
if ( ! file_exists( $dependency_file ) || 0 !== validate_file( $dependency_file ) ) {
if ( validate_path( $dependency_file ) ) {
return [];
}

Expand Down Expand Up @@ -223,7 +223,7 @@ function get_asset_property( string $asset, string $prop ) : ?string {
* @return array The asset map.
*/
function read_asset_map( string $path ) : array {
if ( file_exists( $path ) && 0 === validate_file( $path ) ) {
if ( validate_path( $path ) ) {
ob_start();
include $path; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.IncludingFile, WordPressVIPMinimum.Files.IncludingFile.UsingVariable
return json_decode( ob_get_clean(), true );
Expand Down

0 comments on commit 6fde834

Please sign in to comment.