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

Fixed Beans Compiler path handling on some systems. #334

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion lib/api/compiler/class-beans-compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,21 @@ public function get_internal_content() {
// Replace URL with path.
$fragment = beans_url_to_path( $fragment );

// Stop here if it isn't a valid file.
// Fix path on some Windows and Ubuntu systems.
// @ticket 332.
if ( ! file_exists( $fragment ) || 0 === @filesize( $fragment ) ) { // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- Valid use case.

if ( false !== strpos( $fragment, '/wp-' ) ) {
$fragment = beans_sanitize_path( '.' . $fragment );
}
}

// Account for edge cases not covered before.
if ( ! file_exists( $fragment ) || 0 === @filesize( $fragment ) ) { // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- Valid use case.
$fragment = $this->resolve_fragment_location_by_url_parse( $fragment );
}

// Stop here if it still isn't a valid file.
if ( ! file_exists( $fragment ) || 0 === @filesize( $fragment ) ) { // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- Valid use case.
return false;
}
Expand All @@ -441,6 +455,20 @@ public function get_internal_content() {
return $GLOBALS['wp_filesystem']->get_contents( $fragment );
}

/**
* Resolve an edge case asset location by running through Beans's URL parsing.
*
* @since 1.6.0
* @param string $fragment Unresolved asset fragment path.
*
* @return string The fragment path as modified by URL parsing.
*/
public function resolve_fragment_location_by_url_parse( $fragment ) {
$fragment = beans_path_to_url( $fragment );

return beans_url_to_path( $fragment );
}

/**
* Get external file content.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public function test_should_return_empty_string_when_fragment_does_not_exist() {
Monkey\Functions\when( 'beans_url_to_path' )->returnArg();
Monkey\Functions\when( 'wp_remote_get' )->justReturn();
Monkey\Functions\when( 'is_wp_error' )->justReturn( true );
Monkey\Functions\when( 'is_main_site' )->justReturn();
Monkey\Functions\when( 'get_blog_details' )->justReturn();
Monkey\Functions\when( 'get_current_blog_id' )->justReturn();

// Run the test.
$compiler->combine_fragments();
Expand Down