Bug 24160 - Setting innerHTML to a table element causes table contents to jump out
Summary: Setting innerHTML to a table element causes table contents to jump out
Status: RESOLVED CONFIGURATION CHANGED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2009-02-25 09:13 PST by Seth A. Roby
Modified: 2023-04-11 15:08 PDT (History)
13 users (show)

See Also:


Attachments
testcase (1.18 KB, text/html)
2009-02-25 09:14 PST, Seth A. Roby
no flags Details
Test case for appendChild vs. innerHTML (1.35 KB, text/html)
2012-10-18 15:16 PDT, ± ryan
no flags Details
Safari 15.6 differs from other browsers (939.32 KB, image/png)
2022-08-12 09:32 PDT, Ahmad Saleem
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Seth A. Roby 2009-02-25 09:13:38 PST
I have a <div/> element that I am setting the innerHTML on, and setting it to a string of the form "<table><tbody><tr><div>Content</div></tr></tbody></table>". This is, I know, invalid markup, since it does not contain a <td/> element. But Instead of wraping the <div/> in a <td/>, the <div/> jumps out of the table entirely and precedes it in the DOM.

However, if I have a <table/> element and set innerHTML to "<tbody><tr><div>Content</div></tr></tbody>", the <div/> is wrapped in a <td/> and stays inside the <table/>. 

It's this inconsistency that might be a bug.
Comment 1 Seth A. Roby 2009-02-25 09:14:57 PST
Created attachment 27968 [details]
testcase

testcase showing the different behaviors.
Comment 2 ± ryan 2012-10-18 15:16:01 PDT
Created attachment 169484 [details]
Test case for appendChild vs. innerHTML

I believe this to be a related issue to the on e described in this ticket:

Platform: Mac OS X 10.8.2
Version: =< 537+

Inserting nested form elements (while invalid) results in differing behaviors when using appendChild vs. innerHTML. Compare this behavior to a non-webkit engine like Gecko.
Comment 3 Adam Barth 2012-10-19 14:13:23 PDT
I believe this is the correct behavior w.r.t. the spec.  Have you checked how other browsers that support the HTML5 parsing algorithm behave?
Comment 4 ± ryan 2012-10-19 14:33:16 PDT
Sorry, I wasn't as clear as I should have been in my previous comment:

I'm not sure about how the spec dictates these two methods handle element insertion, but the internally inconsistent behavior of appending via innerHTML is what I believe is at issue. As demonstrated by the test case, only the first nested form element is ignored and not rendered (while still rendering the children). Additional form elements at the same nesting level are rendered normally (or abnormally if you like).
Comment 5 Adam Barth 2012-10-19 15:38:49 PDT
HTML parsing is not internally consistent.  It's sanity in a bottle, but it works.
Comment 6 Ahmad Saleem 2022-08-12 09:32:40 PDT
Created attachment 461563 [details]
Safari 15.6 differs from other browsers

For first test case:

*** Safari Technical Preview 151 ***

Mismatch when setting contents of 'tbody':
Expected: '<tr><td><div></div></td></tr>'
Actual: '<tr></tr><div></div>'

Mismatch when setting contents of 'table':
Expected: '<tr><td><div></div></td></tr>'
Actual: '<tbody><tr></tr></tbody><div></div>'

Mismatch when setting contents of 'div':
Expected: '<table><tbody><tr><div></div></tr></tbody></table>'
Actual: '<div></div><table><tbody><tr></tr></tbody></table>'

*** Firefox Nightly 105 ***

Mismatch when setting contents of 'tbody':
Expected: '<tr><td><div></div></td></tr>'
Actual: '<tr></tr><div></div>'

Mismatch when setting contents of 'table':
Expected: '<tr><td><div></div></td></tr>'
Actual: '<tbody><tr></tr></tbody><div></div>'

Mismatch when setting contents of 'div':
Expected: '<table><tbody><tr><div></div></tr></tbody></table>'
Actual: '<div></div><table><tbody><tr></tr></tbody></table>'

*** Chrome Canary 106 ***

Mismatch when setting contents of 'tbody':
Expected: '<tr><td><div></div></td></tr>'
Actual: '<tr></tr><div></div>'

Mismatch when setting contents of 'table':
Expected: '<tr><td><div></div></td></tr>'
Actual: '<tbody><tr></tr></tbody><div></div>'

Mismatch when setting contents of 'div':
Expected: '<table><tbody><tr><div></div></tr></tbody></table>'
Actual: '<div></div><table><tbody><tr></tr></tbody></table>'

_________

All browsers match in the first test case.

For second, as can be seen from attached, there is space between buttons in Safari while not in other browsers. So there seems to be an issue. I think it is less to do with DOM but more about Layout and Rendering. I am changing status to New for others to decide and update details accordingly. Thanks!
Comment 7 Radar WebKit Bug Importer 2022-08-12 11:03:39 PDT
<rdar://problem/98577534>
Comment 8 Ahmad Saleem 2023-02-09 16:00:20 PST
At least now for 'Test case for appendChild vs. innerHTML', Safari 16.3 matches with other browser from the picture 'Safari 15.6 differs from other browsers'. Just wanted to update. Thanks!
Comment 9 Ahmad Saleem 2023-04-11 15:08:39 PDT
We are matching in both test case with other browsers (Safari 16.4).

Marking this as "RESOLVED CONFIGURATION CHANGED" and CCing 'Karl', 'Ryosuke' and 'Anne' for any input. (If I am wrong).