-
Notifications
You must be signed in to change notification settings - Fork 385
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
Malformed url in links creates an invalid AMP page #977
Comments
Interesting. When validating the AMP Validator just links to https://www.ampproject.org/docs/reference/spec#links which says:
I'm not sure how the validator is understanding a URL like Sanitization of the value should be done in the |
Hi, the validator is complaining about the host, the protocol seems to be correct, it's
There's this code in line 300 which validates that the host doesn't contain any weird character, like a whitespace: for (let ii = 0; ii < unescapedHost.length; ++ii) {
const charCode = unescapedHost.charCodeAt(ii);
if (!hostCharIsValid(charCode)) {
this.isValid = false;
}
}
return unescapedHost; I agree it should be in |
Sounds good! |
I have run into this, too. Other examples seen in the wild during validation:
Might be test case fodder, lemme know if you want help @rubengonzalezmrf |
@rubengonzalezmrf from your comments I assumed you were looking to open a PR? |
@westonruter yes, i've done it already: Pull request #983 |
@davisshaver if a user inputs just text in a link like "foo bar", wordpress automatically prepends the protocol http:// so it's the same case than the So at the end all test cases are the same, the host can't contain whitespaces or other invalid chars |
@rubengonzalezmrf I encountered the issue mentioned above while testing/migrating legacy content. Seems like the editor behavior probably changed since the content was originally produced but I still think the test cases are warranted for backwards compatibility (even if they seem unlikely to happen today). |
I added more test cases and checks. But i don't really know why the unit tests are not passing, the code works in my wordpress installation. I'm sure i'm missing something with the tests, but can't find what it is. Some help would be appreciated |
If an editor ads a link like
<a href="http://foo%20bar">foo bar</a>
by mistake, the generated amp page will be invalid.I think it would be great to add an AMP_Link_Sanitizer class that checks the urls of the links and remove the tag if the url is malformed.
The text was updated successfully, but these errors were encountered: