-
Notifications
You must be signed in to change notification settings - Fork 124
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 erratic $log_file_link and $raw_log_file_link on Debug TAB on Windows #633
base: master
Are you sure you want to change the base?
Conversation
On Windows backslashes in path break the replace. For example $log_file_link becomes: http://example.org/D:/my_sites/example_org/wp-content/cache/view_e1b50ae15624d52670a4a76c4ce03610.php Because ABSPATH value on Windows is: "D:\my_sites\example_org/" therefore it doesn't get replaced with the empty string.
@DrLightman Thanks. I think that's better to we keep str_replace. Anyway, there are two variants which could work:
I use cygwin on Windows and I can't test it at this moment. I'd like to we avoid |
Second try :)
Hi @stodorovic can you check now? I wasn't able to make it shorter, I had to start with: ABSPATH = Also, I don't know if this kind of replacement might break when an user customizes the cache location in the Advanced tab... by moving it outside the document root, is it even possibile, theoretically? |
} else { | ||
$cache_url = str_replace( '\\', '/', $cache_path ); | ||
$cache_url = str_replace( str_replace( '\\', '/', ABSPATH ), '', $cache_url ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've found old laptop with Windows XP/PHP 5.2,5.3,5.4. I've tested following code:
} | |
// Extracts and normalizes relative path. | |
$cache_rel_path = str_replace( realpath( ABSPATH ), '', realpath( $cache_path ) ); | |
$cache_rel_path = str_replace( '\\', '/', $cache_rel_path ); |
It seems OK by first tests and it's more readable. We need only to replace \
because $cache_rel_path
doesn't contain drive letter.
$cache_url = str_replace( '\\', '/', $cache_path ); | ||
$cache_url = str_replace( str_replace( '\\', '/', ABSPATH ), '', $cache_url ); | ||
} | ||
$cache_url = site_url( $cache_url ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$cache_url = site_url( $cache_url ); | |
$cache_url = trailingslashit( site_url( $cache_rel_path ) ); |
It's possible to realpath strips last slash.
I've checked on older PHP versions (windows) and it seems that we could reduce complexity. Could you check my suggestions? Is it working on your installations? |
On Windows backslashes in path break the replace. For example $log_file_link may become something like this:
http://example.org/D:/my_sites/example_org/wp-content/cache/view_e1b50ae15624d52670a4a76c4ce03610.php
Because ABSPATH value on Windows is
D:\my_sites\example_org/
therefore it doesn't get replaced with the empty string.Same goes with $raw_log_file_link since they are being generated in the same manner involving a string replacement.