Skip to content

Commit

Permalink
Improved: handle incorrect query parameters in URLs when processing G…
Browse files Browse the repository at this point in the history
…oogle Fonts.
  • Loading branch information
Dan0sz committed Apr 30, 2024
1 parent b0399c3 commit fbe00d1
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/Frontend/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public function __construct() {
}

/**
* @since v5.3.3 Decode HTML entities to prevent URL decoding issues on some systems.
* @since v5.3.3 Decode HTML entities to prevent URL decoding issues on some systems.
*
* @since v5.4.3 With encoded URLs the Google Fonts API is much more lenient when it comes to invalid requests,
* @since v5.4.3 With encoded URLs the Google Fonts API is much more lenient when it comes to invalid requests,
* but we need the URL to be decoded in order to properly parsed (parse_str() and parse_url()), etc.
* So, as of now, we're trimming invalid characters from the end of the URL. The list will expand
* as I run into to them. I'm not going to make any assumptions on what theme/plugin developers
Expand All @@ -40,6 +40,19 @@ public function __construct() {
* @return string
*/
public function decode_url( $url ) {
return rtrim( html_entity_decode( $url ), ',' );
/**
* Decode for proper processing.
*/
$url = html_entity_decode( $url );
/**
* Fix invalid query parameters.
*/
$url = str_replace( [ ',&', '&,' ], '&', $url );
/**
* Remove trailing commas
*/
$url = rtrim( $url, ',' );

return $url;
}
}

0 comments on commit fbe00d1

Please sign in to comment.