Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal/Critical error - Malformed URL #73

Open
paulocoghi opened this issue Jun 11, 2021 · 2 comments
Open

Fatal/Critical error - Malformed URL #73

paulocoghi opened this issue Jun 11, 2021 · 2 comments

Comments

@paulocoghi
Copy link

paulocoghi commented Jun 11, 2021

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?

@paulocoghi
Copy link
Author

paulocoghi commented Jun 11, 2021

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

@paulocoghi
Copy link
Author

paulocoghi commented Jun 12, 2021

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!

@paulocoghi paulocoghi changed the title Fatal/Critical error - Malformed URL - Publisher theme by Better Studio Fatal/Critical error - Malformed URL Jun 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant