isHTML fails to parse HTML

Issue #1166 resolved
Igor created an issue

isHTML parses as XML rather than HTML.

https://bitbucket.org/geowerkstatt-hamburg/masterportal/src/be95efd9c66c820f4f135a7e8a904fd7e4dcd15c/src/utils/isHTML.js#src/utils/isHTML.js-10

This makes the parses too strict, preventing the rendering of some markup, that is otherwise considered valid HTML when using text/html.

This makes the GFI wrongly output markup as text, rather than rendering it as html. (see link below)


Examples of valid HTML, that fails by parsing as XML:

  • <div>Foobar</div><p>Große Str. 123, 12345 Stadt<br /><a href="https://example.org" class="link">Zum Standort</a></p>
  • <span>Foo</span><span>Bar</span>
  • <p>Foo</p><hr><p>Bar</p>

To test results:

htmlString = `<p>Foo</p>
              <p>Bar</p>`;
errorNode = new DOMParser().parseFromString(htmlString, "text/xml").querySelector("parsererror");
console.log('RESULT:', errorNode ? 'INVALID' : 'VALID');

Note:
text/xml expects a single root node and does fail when parsing multiple nodes like in the examples above.
Using text/html shows that multiple nodes are valid HTML.
Also if rendering a single root is a concern for some reason, should not be a problem given that the parsed string is being rendered inside a <div> that acts itself as root node.

Comments (5)

  1. Carina Brühl

    isHTML will now recognize the given examples of html als valid. These changes will be included in the next release.

  2. Log in to comment