-
Notifications
You must be signed in to change notification settings - Fork 384
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
Invalid validation error and AMP-to-AMP linking failure for mailto: links #4182
Comments
Implementation Hi @westonruter, What do you think about: diff --git a/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php b/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php
index 6786a213d..9227c6a62 100644
--- a/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php
+++ b/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php
@@ -1666,7 +1666,7 @@ class AMP_Tag_And_Attribute_Sanitizer extends AMP_Base_Sanitizer {
* @return string|null Protocol without colon if matched. Otherwise null.
*/
private function parse_protocol( $url ) {
- if ( preg_match( '#^[^/]+(?=:)#', $url, $matches ) ) {
+ if ( preg_match( '#^[^/]+?(?=:)#', $url, $matches ) ) {
return $matches[0];
}
return null; ...and of course I'll add some test cases for this. That changes to the pattern to 'lazily' match For example, with This looks to prevent validation errors in Standard mode for the 2 snippets you added:
And it prevents validation errors in Paired mode on the #4183 branch. Thanks, Weston! |
Yes, that seems like it will work well. Alternatively, instead of
So the hardened regex pattern could be amp-wp/includes/sanitizers/class-amp-allowed-tags-generated.php Lines 462 to 486 in 19d54bd
|
Thanks, Weston! The new regex looks good, in line with actual protocols in |
Able to add QA instructions, @kienstra ? |
Sure, the instructions here should be fine: #4251 (comment) |
Verified in QA |
Bug Description
Add a Custom HTML block that contains the following markup:
This results in the AMP plugin detecting an
INVALID_URL_PROTOCOL
validation error:This is in spite of the markup being entirely valid in AMP:
The issue also happens when an email address is provided:
Please note: the issue only occurs in Standard mode. In Transitional mode, it turns out that the
AMP_Link_Sanitizer
is mutating themailto:
link in a way that causes it to no longer be invalid. This turns out to also be an error, as\AMP_Link_Sanitizer::is_frontend_url()
needs to only apply to URLs with the HTTP and HTTPS scheme. (See #4183 which fixes this so you can test in Transitional mode if checking out that branch.)The reason for why
AMP_Link_Sanitizer
prevents the links from being invalid is that it mutates the URL viaadd_query_arg()
to append?amp
. So it is making this change:The tag-and-attribute sanitizer likes the latter but not the former. But the AMP validator is OK with both, so we need to update our behavior to match. Our validator appears to be failing when the URL contains an unencoded colon (
:
), even though that is perfectly fine.Expected Behaviour
Links with
mailto:
protocol that contain a query parameter that have a URL value get flagged as a validation error.Steps to reproduce
mailto:
link.Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Implementation brief
QA testing instructions
Demo
Changelog entry
The text was updated successfully, but these errors were encountered: