Provide origin for stylesheet URLs which are absolute paths#6257
Provide origin for stylesheet URLs which are absolute paths#6257westonruter wants to merge 7 commits intodevelopfrom
Conversation
027b325 to
c50371f
Compare
|
@westonruter Any update on this? Should we make it ready for the next release? |
|
@thelovekesh Yes, even though nobody else has reported this as an issue, we might as well do it. Feel free to add tests to finish this out. |
|
Plugin builds for a90ef6a are ready 🛎️!
|
|
@westonruter This PR is ready for your review now. |
| */ | ||
| private function get_stylesheet_from_url( $stylesheet_url ) { | ||
| // For absolute paths, provide the origin (host and port). | ||
| if ( '/' === substr( $stylesheet_url, 0, 1 ) && '//' !== substr( $stylesheet_url, 0, 2 ) ) { |
There was a problem hiding this comment.
I just tried disabling this condition and then attempted to run the test to see if the test was asserting the expected case, but the test still passed when this code was disabled. 😕
Looking further, I'm not sure this logic is needed given this logic in get_validated_url_file_path:
amp-wp/includes/sanitizers/class-amp-style-sanitizer.php
Lines 1292 to 1299 in 85a2644
There was a problem hiding this comment.
Hmm. Additionally, I can attest that get_validated_url_file_path precisely covers file path validation. So long as there are no use cases that it cannot handle, we can rely on it and avoid adding additional logic for the same task.
|
Humm. Let's punt this since we haven't received any other reports of it being a need and I can't seem to reproduce it. |
Summary
As discovered in a support topic, if a stylesheet is printed without a hostname, this currently is resulting in a stylesheet fetch error, for example:
This can be simulated with the following PHP plugin code:
The issue is that neither
\AMP_Style_Sanitizer::get_validated_url_file_path()nor\AMP_Style_Sanitizer::fetch_external_stylesheet()are supplying the current host name if the provided$stylesheet_urlis missing one. This can be resolved by prefixing the provided URL with the origin (host and port).Checklist