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

fix relative urls regex in cdn to work with dots #6195

Open
wants to merge 1 commit into
base: develop
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
2 changes: 1 addition & 1 deletion inc/Engine/CDN/CDN.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function rewrite( $html ) {
* @param bool $enable True to enable, false otherwise.
*/
if ( apply_filters( 'rocket_cdn_relative_paths', true ) ) {
$relative_path_pattern = '|\/[^/](?:[^"\')\s>]+\.[[:alnum:]]+)';
$relative_path_pattern = '|(\.+\/|\/)[^/](?:[^"\')\s>]+\.[[:alnum:]]+)';
}

$pattern = '#[("\']\s*(?<url>(?:(?:https?:|)' . preg_quote( $this->get_base_url(), '#' ) . ')\/(?:(?:(?:' . $this->get_allowed_paths() . ')[^"\',)]+))' . $relative_path_pattern . ')\s*["\')]#i';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1044,5 +1044,6 @@ <h1 class="entry-title">Page Image Alignment</h1> </header><!-- .entry-hea
<script type='text/javascript' src='http://example.org/wp-content/themes/storefront/assets/js/vendor/pep.min.js?ver=0.4.3'></script>
<script type='text/javascript' src='http://example.org/wp-includes/js/wp-embed.min.js?ver=5.2.2'></script>
<script src="/wp-content/plugins/test/script.js"></script>
<script src="../wp-content/plugins/test2/script.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -1044,5 +1044,6 @@ <h1 class="entry-title">Page Image Alignment</h1> </header><!-- .entry-hea
<script type='text/javascript' src='http://cdn.example.org/wp-content/themes/storefront/assets/js/vendor/pep.min.js?ver=0.4.3'></script>
<script type='text/javascript' src='http://cdn.example.org/wp-includes/js/wp-embed.min.js?ver=5.2.2'></script>
<script src="http://cdn.example.org/wp-content/plugins/test/script.js"></script>
<script src="http://cdn.example.org/../wp-content/plugins/test2/script.js"></script>
</body>
</html>
4 changes: 4 additions & 0 deletions tests/Fixtures/inc/Engine/CDN/CDN/rewriteUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
'url' =>'/wp-includes/jquery.js',
'expected' => 'https://cdn.example.org/wp-includes/jquery.js',
],
'testRelativePathWithDots' => [
'url' =>'../wp-content/download.jpeg',
'expected' => 'https://cdn.example.org/../wp-content/download.jpeg',
],
'testNoScheme' => [
'url' =>'//example.org/wp-content/uploads/podcast.mp4',
'expected' => '//cdn.example.org/wp-content/uploads/podcast.mp4',
Expand Down
Loading