Skip to content

Commit

Permalink
Image CDN: Prevent URLs from being double encoded (#40886)
Browse files Browse the repository at this point in the history
  • Loading branch information
dilirity authored Jan 14, 2025
1 parent c07eade commit 9b21c70
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions projects/packages/image-cdn/changelog/fix-double-encoding
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

General: Ensure that double encoding doesn't happen.
1 change: 1 addition & 0 deletions projects/packages/image-cdn/src/class-image-cdn-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ public static function is_cdn_url( $url ) {
*/
private static function escape_path( $path ) {
$parts = explode( '/', $path );
$parts = array_map( 'rawurldecode', $parts );
$parts = array_map( 'rawurlencode', $parts );
return implode( '/', $parts );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,16 @@ public function test_photon_url_filter_url_encodes_path_parts() {
$this->assertEquals( 'https://i0.wp.com/example.com/narrow%E2%80%AFno-break%E2%80%AFspace/name%20with%20spaces.jpg', $url );
}

/**
* @covers Automattic\Jetpack\Image_CDN\Image_CDN_Core::cdn_url
* @since $$next-version$$
* @group jetpack_photon_filter_url_encoding
*/
public function test_photon_url_filter_encoded_url_should_not_be_encoded_again() {
$url = Image_CDN_Core::cdn_url( '//example.com/image%20with%20spaces.jpg', array(), 'https' );
$this->assertEquals( 'https://i0.wp.com/example.com/image%20with%20spaces.jpg', $url );
}

/**
* @author aduth
* @covers Automattic\Jetpack\Image_CDN\Image_CDN_Core::cdn_url_scheme
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Image CDN: Ensure that double encoding doesn't happen.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: bugfix

Photon: Fix double encoding image urls.

0 comments on commit 9b21c70

Please sign in to comment.