better-amp
better-amp copied to clipboard
Fatal/Critical error - Malformed URL
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: https://github.com/better-studio/better-amp/blob/fb7bdb0540095a4e8f390f0cebd73f5355fc0b37/includes/functions/utility-function.php#L196-L228
What extra information do you consider important that I mention, in addition to the information above?
I am at your total disposal to provide every additional information needed.
Root cause found When an editor inserts a link to a related article, he can, sometimes, wrongly choose the title instead of the URL. And this is the cause for the malformed URL and the error on the AMP version.
Suggestion: Since the lack of availability of the AMP version represents loss of visits (millions, in this customer case), I would suggest to provide an option to enable the removal of a malformed link and to compile the AMP without it, instead of not compiling it.
In this customer scenario, such feature would be positive, since its editors are mostly non-programmers and non-developers.
You can close this issue, if you want to. Thanks again!