-
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
Validation broken in Genesis themes by Document::normalize_document_structure() #4104
Comments
So as it turns out, the main obstacle here is (again) PHP's I'll need to add additional logic to allow for this, it seems. |
Isn't it the normalize method here that is prepending the doctype by prepending |
I changed the regexes now to take leading comments into account. But as soon as I do that and keep the first comment, I'm experimenting with the best way of getting around this, which seems to be a combination of changing the doctype into a comment and using the |
verified in qa |
Bug Description
I was testing out a Genesis theme and I saw in the admin bar that it was ✅ valid AMP. When I clicked to validate the page, however, I unexpectedly saw two validation errors:
This made no sense to me and I was racking my brain trying to figure it out. It turns out to be that the
link[rel=canonical]
element was located in thebody
during validation, when for non-validation requests it is in thehead
as expected.The issue turns out to be
\Amp\AmpWP\Dom\Document::normalize_document_structure()
introduced in #3758, namely that it is not currently written to account for HTML comments occuring before the doctype.Normally, WordPress themes hard-code the
<!DOCTYPE html>
,<html>
, and<head>
tags. Genesis, however, usesgenesis_doctype()
to generate them. When a validation request is being performed, source stack comments are added before and aftergenesis_doctype()
like so:This has the effect of
Document::normalize_document_structure()
normalizing the document to start as:Expected Behaviour
The DOM used for validation should be normalized to be the same as the DOM used for rendering.
Steps to reproduce
link[rel=canonical]
or other tags.Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
<!DOCTYPE>
,<html>
, and<head>
tags must be preserved so that validation errors can be properly sourced.Implementation brief
<!DOCTYPE>
,<html>
, and<head>
and ensure that they are retained after normalization.QA testing instructions
Demo
Changelog entry
The text was updated successfully, but these errors were encountered: