Enforce unique constraints from validator #2451
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1580.
The sanitizer is not currently enforcing a unique constraint, resulting in validation errors leaking to the frontend when, for example:
meta[charset]
appears more than once: https://wordpress.org/support/topic/amp-error-for-google-webmaster-tools/meta[name=viewport]
appears more than once: https://wordpress.org/support/topic/the-tag-meta-nameviewport-appears-more-than-once-in-the-document-3/amp-geo
appears more than once: Implement unique constraint in whitelist sanitizer #1580.It is straightforward to implement this constraint by merely keeping track of whether or not a given tag spec with the
unique
constraint has been encountered for a given element. If so, then the element should raise a validation error for removal.Before
Given the Page Speed theme:
After
Addendum
Static analysis revealed a variable which may not have been defined, so this is fixed in a917b39.