Edit:
New information on the end of this issue! We found the root cause!
Versions:
Wordpress - 5.7.2
Better AMP - 1.12.0
Ubuntu - 20.04.2
Nginx - 1.19.9
PHP - 7.4 FPM
MariaDB - 10.5 (but the error also occurred when we used MySQL 8 instead of MariaDB)
Theme:
Publisher (by Better Studio) - 7.9.2
Issue:
In the last few months, some AMP pages created by Better AMP present the error below:
Fatal error: Uncaught InvalidArgumentException: Malformed URL:
http://The Post Title With Spaces Instead of a Proper Url in /home/myuser/public_html/wp-content/plugins/better-amp/includes/functions/utility-function.php:218
Stack trace:
#0 /home/myuser/public_html/wp-content/plugins/better-amp/includes/classes/class-better-amp-content-sanitizer.php(968): mb_parse_url()
#1 /home/myuser/public_html/wp-content/plugins/better-amp/includes/classes/class-better-amp-content-sanitizer.php(100): Better_AMP_Content_Sanitizer->sanitize_document()
#2 /home/myuser/public_html/wp-content/plugins/better-amp/better-amp.php(816): Better_AMP_Content_Sanitizer->sanitize()
#3 /home/myuser/public_html/wp-content/plugins/better-amp/better-amp.php(1102): Better_AMP->render_content()
#4 /home/myuser/public_html/wp-includes/class-wp-hook.php(292): Better_AMP->buffer_better_amp_end()
#5 /home/myuser/public_html/wp-includes/class-wp-hook.php(316): WP_Hook->apply_filters()
#6 /home/myuser/public_html/wp-includes/plugin.php(484): WP_Hook->do_action()
#7 /home/my in /home/myuser/public_html/wp-content/plugins/better-amp/includes/functions/utility-function.php on line 218
Observations:
- this doesn't happen on all AMP pages, just a few
- the non-AMP page of the erroneous AMP url works perfectly fine, without errors
- this is happening sometimes on the last few months
- on the error cases, it seems that the URL variable on PHP is coming with the following erroneous format:
http://The Page Title
- we use Yoast SEO Premium (now on v16.4) from the beginning, but most AMP pages have no problem nor errors, so it doesn't seem to be related to Yoast
- we use FastCGI cache on Nginx, but:
- the cache time for each page is really small, and any temporary error would be cleared really fast
- I manually cleared the FastCGI cache on the URLs with errors anyway, to re-check and to provide the detailed error (temporarily enabling the Wordpress debug mode), and it doesn't seem to be related to FastCGI Cache from Nginx
Example URL with error (but with debug disabled)
https://www.dci.com.br/dci-mais/noticias/filme-do-sbt-hoje-11-6-a-princesa-xuxa-e-os-trapalhoes/143275/amp/
Example with working URL
https://www.dci.com.br/investimentos/criptomoedas/twitter-pode-ser-primeira-grande-rede-social-a-integrar-o-bitcoin/143591/amp/
Origin:
|
if ( ! function_exists( 'mb_parse_url' ) ) { |
|
|
|
|
|
/** |
|
* Parse a URL and return its components. |
|
* |
|
* @param string $url |
|
* @param int $component |
|
* |
|
* @since 1.9.13 |
|
* @return array|string|false |
|
*/ |
|
function mb_parse_url( $url, $component = - 1 ) { |
|
|
|
$encodedUrl = preg_replace_callback( '%[^:/@?&=#]+%usD', function ( $matches ) { |
|
return urlencode( $matches[0] ); |
|
}, $url ); |
|
|
|
$parts = parse_url( $encodedUrl, $component ); |
|
|
|
if ( $parts === false ) { |
|
|
|
throw new \InvalidArgumentException( 'Malformed URL: ' . $url ); |
|
} |
|
|
|
if ( ! empty( $parts ) && is_array( $parts ) ) { |
|
|
|
$parts = array_map( 'urldecode', $parts ); |
|
} |
|
|
|
return $parts; |
|
} |
|
} |
What extra information do you consider important that I mention, in addition to the information above?
Edit:
New information on the end of this issue! We found the root cause!
Versions:
Wordpress - 5.7.2
Better AMP - 1.12.0
Ubuntu - 20.04.2
Nginx - 1.19.9
PHP - 7.4 FPM
MariaDB - 10.5 (but the error also occurred when we used MySQL 8 instead of MariaDB)
Theme:
Publisher (by Better Studio) - 7.9.2
Issue:
In the last few months, some AMP pages created by Better AMP present the error below:
Observations:
http://The Page TitleExample URL with error (but with debug disabled)
https://www.dci.com.br/dci-mais/noticias/filme-do-sbt-hoje-11-6-a-princesa-xuxa-e-os-trapalhoes/143275/amp/
Example with working URL
https://www.dci.com.br/investimentos/criptomoedas/twitter-pode-ser-primeira-grande-rede-social-a-integrar-o-bitcoin/143591/amp/
Origin:
better-amp/includes/functions/utility-function.php
Lines 196 to 228 in fb7bdb0
What extra information do you consider important that I mention, in addition to the information above?