Bug 156637

Summary: Cloning a textarea does not clone the textarea's value
Product: WebKit Reporter: Myles C. Maxfield <mmaxfield>
Component: FormsAssignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, annevk, ap, cdumez, commit-queue, darin, dbates, eoconnor, philipj, rbyers, rniwa, sam
Priority: P2    
Version: Other   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Reproduction
none
Patch
none
Patch
none
Patch
none
Archive of layout-test-results from ews114 for mac-yosemite
none
Patch none

Description Myles C. Maxfield 2016-04-15 12:54:22 PDT
Created attachment 276497 [details]
Reproduction

Open the attached .html file. It should alert "a" twice.
Comment 1 Myles C. Maxfield 2016-04-15 12:55:09 PDT
Note that fixing this bug should include making sure checkValidity() works correctly.
Comment 2 Myles C. Maxfield 2016-04-15 13:00:17 PDT
(In reply to comment #1)
> Note that fixing this bug should include making sure checkValidity() works
> correctly.

fast/forms/checkValidity-cloneNode-crash.html should be updated when this occurs.
Comment 3 Chris Dumez 2016-04-16 20:25:00 PDT
Firefox and Safari alert "a" once.
Chrome alerts "a" twice.
Comment 4 Chris Dumez 2016-04-16 20:38:26 PDT
Myles, why do you expect the textarea cloning to clone the value? I am looking at the spec but I cannot find the part that says we should (maybe I missed it or maybe it is a bug in the spec).

There is what I found in the spec:
https://dom.spec.whatwg.org/#concept-node-clone

-> Says we should copy over all the element attributes, but 'value' is not a content attribute of textarea.
-> Says to run any cloning steps defined for the element in other applicable specifications

So I looked at the HTML spec for HTMLTextAreaElement but it does not seem to define any additional cloning steps:
https://html.spec.whatwg.org/multipage/forms.html#htmltextareaelement

The only cloning steps I find on this page are:
"The cloning steps for input elements must propagate the value, dirty value flag, checkedness, and dirty checkedness flag from the node being cloned to the copy."

However, HTMLTextAreaElement is not an input element (HTMLInputElement).

So, unless I am mistaken, Firefox and Safari/WebKit both match the specification.
Assuming I did not miss anything and you think we should clone the value, I suggest filing a bug against the HTML spec.
Comment 5 Ryosuke Niwa 2016-04-17 17:16:48 PDT
As far as I read the spec, this is a bug in Chrome and WebKit/Gecko behavior is what the spec mandates.

It's somewhat surprising that input element's value is propagated during cloning.
Comment 6 Anne van Kesteren 2016-04-17 23:09:52 PDT
Per HTML only <input>, <template>, and <script> have special cloning behavior. Rick, Philip, any idea why Chrome has this behavior for <textarea>?
Comment 7 Philip Jägenstedt 2016-04-25 13:24:08 PDT
To begin with, here's the code:
https://chromium.googlesource.com/chromium/src/+blame/8400b8124886e7c94ce59b2e595ae74cee821f56/third_party/WebKit/Source/core/html/HTMLTextAreaElement.cpp#641

That was added in response to this bug:
https://bugs.chromium.org/p/chromium/issues/detail?id=487352

I haven't dug deeper into how this turned out this way, but will comment on the bug and point here.
Comment 8 Ryosuke Niwa 2016-04-25 16:27:24 PDT
Closing this bug as won't fix since WebKit's current behavior matches the spec and Gecko's behavior.  Given this Chrome not matching the spec appears to be unintentional, I don't think we should change our behavior.
Comment 9 Myles C. Maxfield 2016-04-25 20:42:47 PDT
Rather than closing the bug now, if we will proceed by considering this a supported operation, we should add a test.
Comment 10 Myles C. Maxfield 2016-04-25 20:47:29 PDT
Reopening to attach new patch.
Comment 11 Myles C. Maxfield 2016-04-25 20:47:32 PDT
Created attachment 277322 [details]
Patch
Comment 12 Ryosuke Niwa 2016-04-25 20:48:56 PDT
Comment on attachment 277322 [details]
Patch

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

We should probably add a more direct test for cloneNode which checks that the value property doesn't get copied over.

> LayoutTests/ChangeLog:7
> +

Please add a change log description.
Comment 13 Chris Dumez 2016-04-25 20:49:05 PDT
Comment on attachment 277322 [details]
Patch

r=me
Comment 14 Myles C. Maxfield 2016-04-25 20:49:38 PDT
Created attachment 277323 [details]
Patch
Comment 15 Myles C. Maxfield 2016-04-25 20:51:47 PDT
Committed r200069: <http://trac.webkit.org/changeset/200069>
Comment 16 Daniel Bates 2016-04-28 23:11:36 PDT
Comment on attachment 277323 [details]
Patch

Clearing review flag given that this patch landed by comment #15.
Comment 17 Chris Dumez 2016-05-11 09:45:53 PDT
Spec discussion on this:
https://github.com/whatwg/html/issues/1233
Comment 18 Chris Dumez 2016-09-15 10:56:33 PDT
Reopen given that the spec was updated got add cloning steps for Textarea:
https://github.com/whatwg/html/pull/1784
Comment 19 Chris Dumez 2016-09-15 12:36:51 PDT
Created attachment 288984 [details]
Patch
Comment 20 Build Bot 2016-09-15 13:47:50 PDT
Comment on attachment 288984 [details]
Patch

Attachment 288984 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/2081456

New failing tests:
fast/forms/checkValidity-cloneNode-crash.html
Comment 21 Build Bot 2016-09-15 13:47:55 PDT
Created attachment 288992 [details]
Archive of layout-test-results from ews114 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews114  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 22 Sam Weinig 2016-09-15 14:27:54 PDT
Comment on attachment 288984 [details]
Patch

Causing crashes.
Comment 23 Chris Dumez 2016-09-15 14:52:39 PDT
Created attachment 289003 [details]
Patch
Comment 24 Chris Dumez 2016-09-15 14:53:15 PDT
Comment on attachment 289003 [details]
Patch

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

> Source/WebCore/html/HTMLTextAreaElement.cpp:598
> +    updateValidity();

I was missing a call to updateValidity() here.
Comment 25 Daniel Bates 2016-09-15 18:51:34 PDT
Comment on attachment 289003 [details]
Patch

Please file a new bug for this patch. This patch represents a change of behavior. We should not re-open this bug, which was fixed 5 months ago (comment #15) to conform to the spec. at the time.
Comment 26 Chris Dumez 2016-09-15 18:57:22 PDT
Comment on attachment 289003 [details]
Patch

No, this bug was opened for this purpose, as per the title. At the time, we decided to hold off on making this change (and file a bug upstream). But now that the spec has been updated, we should do it.

This is also the bug that is tracked upstream (by spec editors).
Comment 27 Chris Dumez 2016-09-16 09:34:44 PDT
Comment on attachment 289003 [details]
Patch

Clearing flags on attachment: 289003

Committed r206026: <http://trac.webkit.org/changeset/206026>
Comment 28 Chris Dumez 2016-09-16 09:34:50 PDT
All reviewed patches have been landed.  Closing bug.