Skip to content

Commit

Permalink
Add support for Windows filepaths
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinfodness committed Dec 18, 2023
1 parent 35e6eb0 commit c470aad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions byline-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 c470aad

Please sign in to comment.