Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Setting HTMLInputElement.value to null to set its value to the empty …
…string

https://bugs.webkit.org/show_bug.cgi?id=153519

Reviewed by Ryosuke Niwa.

Source/WebCore:

Setting HTMLInputElement.value to null to set its value to the empty string:
- https://html.spec.whatwg.org/#htmlinputelement
- http://heycam.github.io/webidl/#TreatNullAs

WebKit would previously unset the value attribute instead, which caused
it to fallback to input.defaultValue if set.

Firefox and Chrome behave correctly.

Test: fast/dom/HTMLInputElement/input-value-set-null.html

* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::setValue):

LayoutTests:

Add a layout test to make sure that setting HTMLInputElement.value to null
actually sets its value to the empty string.

* fast/dom/HTMLInputElement/input-value-set-null-expected.txt: Added.
* fast/dom/HTMLInputElement/input-value-set-null.html: Added.


Canonical link: https://commits.webkit.org/171589@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@195642 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed Jan 27, 2016
1 parent 14d3e53 commit 9065353
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
13 changes: 13 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,16 @@
2016-01-26 Chris Dumez <cdumez@apple.com>

Setting HTMLInputElement.value to null to set its value to the empty string
https://bugs.webkit.org/show_bug.cgi?id=153519

Reviewed by Ryosuke Niwa.

Add a layout test to make sure that setting HTMLInputElement.value to null
actually sets its value to the empty string.

* fast/dom/HTMLInputElement/input-value-set-null-expected.txt: Added.
* fast/dom/HTMLInputElement/input-value-set-null.html: Added.

2016-01-26 Chris Dumez <cdumez@apple.com>

Unreviewed, temporarily skip fast/history/page-cache-webdatabase-no-transaction-db.html
Expand Down
@@ -0,0 +1,13 @@
Checks that setting input.value to null sets the input value to the empty string.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


input.defaultValue = 'defaultValue'
PASS input.value is "defaultValue"
input.value = null
PASS input.value is ""
PASS successfullyParsed is true

TEST COMPLETE

15 changes: 15 additions & 0 deletions LayoutTests/fast/dom/HTMLInputElement/input-value-set-null.html
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<script src="../../../resources/js-test-pre.js"></script>
<script>
description("Checks that setting input.value to null sets the input value to the empty string.");

var input = document.createElement("input");
evalAndLog("input.defaultValue = 'defaultValue'");

shouldBeEqualToString("input.value", "defaultValue");

// HTMLInputElement.value treats null as the empty String so this should set the value to "".
evalAndLog("input.value = null");
shouldBeEqualToString("input.value", "");
</script>
<script src="../../../resources/js-test-post.js"></script>
21 changes: 21 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,24 @@
2016-01-26 Chris Dumez <cdumez@apple.com>

Setting HTMLInputElement.value to null to set its value to the empty string
https://bugs.webkit.org/show_bug.cgi?id=153519

Reviewed by Ryosuke Niwa.

Setting HTMLInputElement.value to null to set its value to the empty string:
- https://html.spec.whatwg.org/#htmlinputelement
- http://heycam.github.io/webidl/#TreatNullAs

WebKit would previously unset the value attribute instead, which caused
it to fallback to input.defaultValue if set.

Firefox and Chrome behave correctly.

Test: fast/dom/HTMLInputElement/input-value-set-null.html

* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::setValue):

2016-01-26 Anders Carlsson <andersca@apple.com>

WebKitAdditions should be able to modify derived source rules
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/html/HTMLInputElement.cpp
Expand Up @@ -983,7 +983,7 @@ void HTMLInputElement::setValue(const String& value, ExceptionCode& ec, TextFiel
ec = INVALID_STATE_ERR;
return;
}
setValue(value, eventBehavior);
setValue(value.isNull() ? emptyString() : value, eventBehavior);
}

void HTMLInputElement::setValue(const String& value, TextFieldEventBehavior eventBehavior)
Expand Down

0 comments on commit 9065353

Please sign in to comment.