Skip to content

Commit 0155a54

Browse files
committed
Fix URL encoding in Link HTTP response header
Signed-off-by: Shyamsundar Gadde <[email protected]>
1 parent db322a3 commit 0155a54

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

plugins/optimization-detective/class-od-link-collection.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,19 +325,17 @@ function ( $image_candidate ) {
325325
*
326326
* @since n.e.x.t
327327
*
328-
* @param string $url URL to percent encode. Any existing percent encodings will first be decoded.
328+
* @param string $url URL to percent encode.
329329
* @return string Percent-encoded URL.
330330
*/
331331
private function encode_url_for_response_header( string $url ): string {
332-
$decoded_url = urldecode( $url );
333-
334332
// Encode characters not allowed in a URL per RFC 3986 (anything that is not among the reserved and unreserved characters).
335333
$encoded_url = (string) preg_replace_callback(
336-
'/[^A-Za-z0-9\-._~:\/?#\[\]@!$&\'()*+,;=]/',
334+
'/[^A-Za-z0-9\-._~:\/?#\[\]@!$&\'()*+,;=%]/',
337335
static function ( $matches ) {
338336
return rawurlencode( $matches[0] );
339337
},
340-
$decoded_url
338+
$url
341339
);
342340
return esc_url_raw( $encoded_url );
343341
}

0 commit comments

Comments
 (0)