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

Parsing does not appear to handle optional tags #954

Open
rzane opened this issue Jun 27, 2023 · 0 comments
Open

Parsing does not appear to handle optional tags #954

rzane opened this issue Jun 27, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@rzane
Copy link

rzane commented Jun 27, 2023

Describe the bug
Certain HTML tags can be omitted. See here: https://www.w3.org/TR/2011/WD-html5-20110525/syntax.html#optional-tags.

To Reproduce
This script reproduces the problem. Note that <option value="PA">Pennsylvania does not have a closing tag. This is allowed because:

An option element's end tag may be omitted if the option element is immediately followed by another option element, or if it is immediately followed by an optgroup element, or if there is no more content in the parent element.

const { Window } = require('happy-dom');

const window = new Window()
window.document.write(`<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Test</title>
  </head>

  <body>
    <select id="states">
      <option value="PA">Pennsylvania
    </select>

    <select id="cities">
      <option>Philadelphia</option>
    </select>
  </body>
</html>`);

console.log(window.document.documentElement.outerHTML);

This will produce the following output. Note that <option>Philadelphia</option> appears outside of the <select> element.

<html lang="en">
  <head>
    <title>Test</title>
  </head>

  <body>
    <select id="states">
      <option value="PA">Pennsylvania
    

    </option></select><select id="cities">
      </select>
<option>Philadelphia</option>
    
  
</body></html>

Expected behavior
Here's the output from JSDOM:

<html lang="en"><head>
    <title>Test</title>
  </head>

  <body>
    <select id="states">
      <option value="PA">Pennsylvania
    </option></select>

    <select id="cities">
      <option>Philadelphia</option>
    </select>
  
</body></html>

Screenshots
If applicable, add screenshots to help explain your problem.

Device:

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@rzane rzane added the bug Something isn't working label Jun 27, 2023
jacobbuck added a commit to jacobbuck/dom-parse that referenced this issue Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant