RESOLVED FIXED 30083
Data loss occurs when unbolding nested bold tags.
https://bugs.webkit.org/show_bug.cgi?id=30083
Summary Data loss occurs when unbolding nested bold tags.
Michael Thomas
Reported 2009-10-05 11:07:22 PDT
Go to the midas demo: http://mozilla.org/editor/midasdemo/ Edit the html source. Enter the following html snippet: <b id="foo">1<b>2</b></b> Switch out of html edit mode. Highlight the "12" and hit unbold. Note that the "2" is gone.
Attachments
demonstrates the bug (825 bytes, text/html)
2009-10-17 20:38 PDT, Ryosuke Niwa
no flags
Fixes the loop in swapInNodePreservingAttributesAndChildren (4.09 KB, patch)
2009-10-17 21:38 PDT, Ryosuke Niwa
eric: review+
eric: commit-queue-
Ryosuke Niwa
Comment 2 2009-10-05 15:59:31 PDT
Mn... this seems to be caused by ApplyStyleCommand. Do you think this is a regression?
Annie Sullivan
Comment 3 2009-10-05 16:02:54 PDT
My test case works fine in Safari 3.2/Win, so I think it's a regression, but maybe not a recent one.
Tancred Lindholm
Comment 4 2009-10-07 01:11:52 PDT
Note that the bug reproduces with *any* attribute in the outer tag, and with other inline style tags, such as at least <i>. Sample cases: <i id=foo>1<i>2</i></i> <b class=foo>1<b>2</b></b> <i lang=en>1<i>2</i></i> <b lang=en id=1>1<b>2</b></b> <b title="Bold text">1<b>2</b></b>
Joseph Holsten
Comment 5 2009-10-17 19:05:44 PDT
What needs to be done to reduce this test case? Seems pretty well reduced to me. I'm a bit new to this testing bit, sorry.
Ryosuke Niwa
Comment 6 2009-10-17 20:38:29 PDT
Created attachment 41368 [details] demonstrates the bug The attached file will hit ASSERT on L1466@ApplyStyleCommand.cpp. ASSERT(s.node()->inDocument()); in ApplyStyleCommand::removeInlineStyle(PassRefPtr<CSSMutableStyleDeclaration> style, const Position &start, const Position &end).
Ryosuke Niwa
Comment 7 2009-10-17 21:07:21 PDT
It turned out that replaceWithSpanOrRemoveIfWithoutAttributes is the one deleting <b>2</b> when called on the outer b element.
Ryosuke Niwa
Comment 8 2009-10-17 21:38:28 PDT
Created attachment 41369 [details] Fixes the loop in swapInNodePreservingAttributesAndChildren It turned out that the bug resided in swapInNodePreservingAttributesAndChildren: https://trac.webkit.org/browser/trunk/WebCore/editing/ReplaceNodeWithSpanCommand.cpp#L60 60 for (Node* child = nodeToReplace->firstChild(); child; child = child->nextSibling()) { 61 newNode->appendChild(child, ec); 62 ASSERT(!ec); 63 } As soon as we appendChild to newNode in L61, nextSibling() is changed to 0. In my patch, I introduced Node* nextChild to temporarily save the pointer.
Eric Seidel (no email)
Comment 9 2009-10-19 14:32:57 PDT
Comment on attachment 41369 [details] Fixes the loop in swapInNodePreservingAttributesAndChildren This would be much better as a test which showed PASS or FAIL. script-test style tests could do that. I might have written this a while loop instead. But the current for seems fine. You might want a comment there: 62 nextChild = child->nextSibling(); // Save nextSibling() as appendChild(child) will change child->nextSibling(). r+, but consider making this a script-test and adding a comment.
Eric Seidel (no email)
Comment 10 2009-10-19 15:19:46 PDT
Comment on attachment 41369 [details] Fixes the loop in swapInNodePreservingAttributesAndChildren Marking cq- since I've asked Ryosuke to consider further changes.
Ryosuke Niwa
Comment 11 2009-10-21 14:25:07 PDT
While converting the test to a js test, I found another bug. WebKit fails to unbold <b><b>hello</b>world</b> because in this case font-weight: 800 and won't match 'bold'. I'm thinking to modify the change so that we check whether the font-weight is normal or not but this might have some weird side-effect. We could fix in a separate patch but I much rather fix it in this patch than having to rebaseline the test later. Eric & Justin, any opinion on this?
Ryosuke Niwa
Comment 12 2009-10-21 14:29:12 PDT
(In reply to comment #11) > modify the change so that we check whether the I mean to say modify the check. i.e. reverse the order of "normal" and "bold" passed to executeToggleBold.
Ryosuke Niwa
Comment 13 2009-10-26 15:32:47 PDT
Talked with Eric on IRC. I committed this patch with new js test that demonstrates the bug I mentioned (WebKit can't unbold <b><b>hello</b></b>), see Bug 30784 for the detail.
Ryosuke Niwa
Comment 14 2009-10-26 15:33:30 PDT
Note You need to log in before you can comment on or make changes to this bug.