Bug 117779

Summary: HTML parser should not associate elements inside templates with forms
Product: WebKit Reporter: Ryosuke Niwa <rniwa>
Component: DOMAssignee: Ryosuke Niwa <rniwa>
Status: RESOLVED FIXED    
Severity: Normal CC: adamk, ap, benjamin, buildbot, commit-queue, eoconnor, esprehn+autocc, gyuyoung.kim, kling, koivisto, rniwa, sam
Priority: P2 Keywords: BlinkMergeCandidate
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 123851    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
buildbot: commit-queue-
Archive of layout-test-results from webkit-ews-13 for mac-mountainlion-wk2
none
Fixed the bug by negating the boolean logic none

Description Ryosuke Niwa 2013-06-18 20:41:42 PDT
Merge https://chromium.googlesource.com/chromium/blink/+/45aadf7ee7ee010327eb692066cf013315ef3ed7

When parsing <form><template><input>, the previous behavior was to associate
the <input> with the <form>, even though they're not in the same tree (or
even the same document!).

This patch changes that by checking, prior to creating a form control element,
whether the element to be created lives in a document with a browsing context.
Comment 1 Ryosuke Niwa 2013-11-19 23:45:00 PST
Created attachment 217392 [details]
Patch
Comment 2 Ryosuke Niwa 2013-11-19 23:46:35 PST
Created attachment 217393 [details]
Patch
Comment 3 Antti Koivisto 2013-11-20 16:32:04 PST
Comment on attachment 217393 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=217393&action=review

> Source/WebCore/html/parser/HTMLConstructionSite.cpp:548
> -    RefPtr<Element> element = HTMLElementFactory::createElement(tagName, ownerDocumentForCurrentNode(), form(), true);
> +    Document& ownerDocument = ownerDocumentForCurrentNode();
> +    bool ownerDocumentHasBrowsingContext = !!ownerDocument.frame();
> +    RefPtr<Element> element = HTMLElementFactory::createElement(tagName, ownerDocument, ownerDocumentHasBrowsingContext ? form() : 0, true);

I'm not entirely sure this is the best way to do this. Shouldn't m_form be null if it does not apply in the current context?

ownerDocumentHasBrowsingContext boolean seems unnecessary.
0 -> nullptr
Comment 4 Ryosuke Niwa 2013-11-20 16:36:17 PST
(In reply to comment #3)
> (From update of attachment 217393 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=217393&action=review
> 
> > Source/WebCore/html/parser/HTMLConstructionSite.cpp:548
> > -    RefPtr<Element> element = HTMLElementFactory::createElement(tagName, ownerDocumentForCurrentNode(), form(), true);
> > +    Document& ownerDocument = ownerDocumentForCurrentNode();
> > +    bool ownerDocumentHasBrowsingContext = !!ownerDocument.frame();
> > +    RefPtr<Element> element = HTMLElementFactory::createElement(tagName, ownerDocument, ownerDocumentHasBrowsingContext ? form() : 0, true);
> 
> I'm not entirely sure this is the best way to do this. Shouldn't m_form be null if it does not apply in the current context?
> 
> ownerDocumentHasBrowsingContext boolean seems unnecessary.
> 0 -> nullptr

That's a good point. Let me dig into it.
Comment 5 Ryosuke Niwa 2013-11-20 20:58:49 PST
Created attachment 217516 [details]
Patch
Comment 6 Ryosuke Niwa 2013-11-20 21:40:02 PST
We can't update m_form because HTMLTreeBuilder::processIsindexStartTagForInBody uses it.

I've asked why this behavior is desirable for isindex on WHATWG:
http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2013-November/041616.html

If the spec. changes to also change is index's behavior we can match update our code accordingly.  Until then, we should land this patch so that our behavior matches that of Chrome & Firefox.
Comment 7 Build Bot 2013-11-20 21:51:04 PST
Comment on attachment 217516 [details]
Patch

Attachment 217516 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/32028027

New failing tests:
fast/forms/formmove3.html
fast/parser/form-pointer-4.html
fast/forms/preserveFormDuringResidualStyle.html
fast/parser/form-pointer-1.html
fast/parser/form-pointer-2.html
fast/forms/parser-associated-form-removal.html
fast/dom/HTMLTemplateElement/no-form-association.html
Comment 8 Build Bot 2013-11-20 21:51:06 PST
Created attachment 217517 [details]
Archive of layout-test-results from webkit-ews-13 for mac-mountainlion-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: webkit-ews-13  Port: mac-mountainlion-wk2  Platform: Mac OS X 10.8.5
Comment 9 Ryosuke Niwa 2013-11-20 21:55:30 PST
Created attachment 217518 [details]
Fixed the bug by negating the boolean logic
Comment 10 WebKit Commit Bot 2013-11-21 05:41:10 PST
Comment on attachment 217518 [details]
Fixed the bug by negating the boolean logic

Clearing flags on attachment: 217518

Committed r159618: <http://trac.webkit.org/changeset/159618>
Comment 11 WebKit Commit Bot 2013-11-21 05:41:13 PST
All reviewed patches have been landed.  Closing bug.