Skip to content
This repository has been archived by the owner on Apr 4, 2019. It is now read-only.

parseHTML disregards browser generated omitted start tags #89

Closed

Conversation

mixonic
Copy link
Collaborator

@mixonic mixonic commented Sep 9, 2014

The HTML spec allows for "omitted start tags". These tags are optional when their intended child is the first thing in the parent tag. For example, this is a tbody start tag:

<table>
  <tbody>
    <tr>

The tbody may be omitted, and the browser will accept and render:

<table>
  <tr>

However, the omitted start tag will still be added to the DOM. We now test the string and context to see if the browser is about to perform this cleanup, with a special allowance for disregarding <script tags.

http://www.whatwg.org/specs/web-apps/current-work/multipage/syntax.html#optional-tags describes which tags are omittable. The spec for tbody and colgroup explains this behavior:

http://www.whatwg.org/specs/web-apps/current-work/multipage/tables.html#the-tbody-element
http://www.whatwg.org/specs/web-apps/current-work/multipage/tables.html#the-colgroup-element

With aid from @bantic. tl;dr the spec will show you the way.

The HTML spec allows for "omitted start tags". These tags are optional
when their intended child is the first thing in the parent tag. For
example, this is a tbody start tag:

```
<table>
  <tbody>
    <tr>
```

The tbody may be omitted, and the browser will accept and render:

```
<table>
  <tr>
```

However, the omitted start tag will still be added to the DOM. We now
test the string and context to see if the browser is about to
perform this cleanup, with a special allowance for disregarding
`<script` tags.

http://www.whatwg.org/specs/web-apps/current-work/multipage/syntax.html#optional-tags
describes which tags are omittable. The spec for tbody and colgroup
explains this behavior:

http://www.whatwg.org/specs/web-apps/current-work/multipage/tables.html#the-tbody-element
http://www.whatwg.org/specs/web-apps/current-work/multipage/tables.html#the-colgroup-element

With aid from @bantic. tl;dr the spec will show you the way.
@mixonic
Copy link
Collaborator Author

mixonic commented Sep 9, 2014

Almost, not quite, one moment.

@mixonic
Copy link
Collaborator Author

mixonic commented Sep 9, 2014

Upon further reflection, though this fix is quite workable it is not correctly put in dom helper. The special handling of <script is actually against the spec, and if we need it just for Handlebars templates in Ember then we should not be breaking spec here.

@mixonic mixonic closed this Sep 9, 2014
@mixonic
Copy link
Collaborator Author

mixonic commented Sep 10, 2014

This is a cleaner version of emberjs/ember.js#5571. In Ember, we ignore <script></script> at the start of a string for Handlebars morphs, which bends the HTML spec suggestions. In HTMLBars we should be stricter.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant