better-studio / better-amp

Full Google AMP support for WordPress with custom themes and customizations
https://betterstudio.com/wp-plugins/better-amp/
GNU General Public License v2.0
19 stars 19 forks source link

Fatal/Critical error - Malformed URL #73

Open paulocoghi opened 3 years ago

paulocoghi commented 3 years ago

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:

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?

paulocoghi commented 3 years ago

I am at your total disposal to provide every additional information needed.

paulocoghi commented 3 years ago

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!