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

[2.9.2] Equivalent HTML does not pass block validation #7032

Closed
mzorz opened this issue May 30, 2018 · 1 comment
Closed

[2.9.2] Equivalent HTML does not pass block validation #7032

mzorz opened this issue May 30, 2018 · 1 comment

Comments

@mzorz
Copy link
Contributor

mzorz commented May 30, 2018

Describe the bug
A block that is created in Gutenberg with a start and end tag, but with no content in between, could be re-written with a self-closing tag, but it fails to pass validation.
For example, when you create an audio Gutenberg block it produces the following HTML:

<!-- wp:audio {"id":450} -->
<figure class="wp-block-audio"><audio controls src="https://domain.com/content.mp3"></audio></figure>
<!-- /wp:audio -->

This is essentially equivalent to the following:

<!-- wp:audio {"id":450} -->
<figure class="wp-block-audio"><audio controls src="http://domain.com/content.mp3" /></figure>
<!-- /wp:audio -->

See the only difference between these 2 equivalent HTML pieces of code is I moved from the <audio></audio> format to the self-closing <audio /> tag.

This is perfectly valid and equivalent HTML, but Gutenberg doesn’t like it and shows the This block appears to have been modified externally dialog.

This is a problem when opening a GB block on any HTML editor, just parsing it out and re-representing it on equivalent HTML presents this problem.

I’ve been checking a bit how this turns out to be on Gutenberg side, and found the comparison is based on method isEquivalentHTML here. What I understand that’s doing is it compares each token to an expected token, and of course it fails to find the ending token for <audio> tag, thus returning false and triggering the error dialog.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new draft and insert an audio block
  2. Switch to HTML view mode
  3. Remove the ending </audio> tag and close the opening tag withn />.
  4. Switch back to visual mode
  5. See the error dialog appears

Expected behavior
Equivalent HTML should be taken as equivalent and pass block validation. I'm not expecting very complex checks here, but a start/closing tag with nothing in between should be equivalent to a self-closing tag for all matters.

Desktop (please complete the following information):

  • OS: [macOS High Sierra 10.13.14]
  • Browser [Chrome]
  • Version [66.0.3359.181 ]

Additional context

  • Gutenberg version 2.9.2
@mtias
Copy link
Member

mtias commented May 31, 2018

Closing the loop here — the problem is self-closing (void) audio is considered invalid HTML. Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio

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

2 participants