Changeset 67164 in webkit
- Timestamp:
- Sep 9, 2010 9:49:09 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r67163 r67164 1 2010-09-09 Kent Tamura <tkent@chromium.org> 2 3 Reviewed by Dimitri Glazkov. 4 5 <input type=number> should not have an invalid number as its value 6 https://bugs.webkit.org/show_bug.cgi?id=43973 7 8 * fast/forms/ValidityState-rangeOverflow-expected.txt: 9 * fast/forms/ValidityState-rangeUnderflow-expected.txt: 10 * fast/forms/ValidityState-typeMismatch-number-expected.txt: 11 * fast/forms/input-number-commit-valid-only-expected.txt: Added. 12 * fast/forms/input-number-commit-valid-only.html: Added. 13 * fast/forms/script-tests/ValidityState-typeMismatch-number.js: 14 * fast/forms/script-tests/input-number-commit-valid-only.js: Added. 15 1 16 2010-09-09 Tony Gentilcore <tonyg@chromium.org> 2 17 -
trunk/LayoutTests/fast/forms/ValidityState-rangeOverflow-expected.txt
r66355 r67164 64 64 PASS The value "99" doesn't overflow the maximum value "1E+2". 65 65 PASS The value "0.99" doesn't overflow the maximum value "1.00". 66 PASS The value " abc" doesn't overflow the maximum value "100".66 PASS The value "" doesn't overflow the maximum value "100". 67 67 PASS The value "" doesn't overflow the maximum value "-1". 68 68 PASS The value "101" doesn't overflow the maximum value "". -
trunk/LayoutTests/fast/forms/ValidityState-rangeUnderflow-expected.txt
r56242 r67164 64 64 PASS The value "101" doesn't underflow the minimum value "1E+2". 65 65 PASS The value "1.01" doesn't underflow the minimum value "1.00". 66 PASS The value " abc" doesn't underflow the minimum value "100".66 PASS The value "" doesn't underflow the minimum value "100". 67 67 PASS The value "" doesn't underflow the minimum value "1". 68 68 PASS The value "-1" doesn't underflow the minimum value "". -
trunk/LayoutTests/fast/forms/ValidityState-typeMismatch-number-expected.txt
r48163 r67164 4 4 5 5 6 PASS 0 is a correctvalid number.7 PASS 10 is a correctvalid number.8 PASS 01 is a correctvalid number.9 PASS -0 is a correctvalid number.10 PASS -1.2 is a correctvalid number.11 PASS 1.2E10 is a correctvalid number.12 PASS 1.2E-10 is a correctvalid number.13 PASS 1.2E+10 is a correctvalid number.14 PASS 12345678901234567890123456789012345678901234567890 is a correctvalid number.15 PASS 0.12345678901234567890123456789012345678901234567890 is a correctvalid number.16 PASS abc is a correct invalid number.17 PASS 0xff is a correct invalid number.18 PASS +1 is a correct invalid number.19 PASS 10 is a correct invalid number.20 PASS 10 is a correct invalid number.21 PASS 1,2 is a correct invalid number.22 PASS .2 is a correct invalid number.23 PASS 1E is a correct invalid number.24 PASS NaN is a correct invalid number.25 PASS nan is a correct invalid number.26 PASS Inf is a correct invalid number.27 PASS inf is a correct invalid number.28 PASS Infinity is a correct invalid number.29 PASS infinity is a correct invalid number.30 PASS is a correctvalid number.31 PASS 1.2E65535 is a correct invalid number.32 PASS 1. is a correctvalid number.33 PASS 1.2e10 is a correctvalid number.6 PASS "0" is a valid number. 7 PASS "10" is a valid number. 8 PASS "01" is a valid number. 9 PASS "-0" is a valid number. 10 PASS "-1.2" is a valid number. 11 PASS "1.2E10" is a valid number. 12 PASS "1.2E-10" is a valid number. 13 PASS "1.2E+10" is a valid number. 14 PASS "12345678901234567890123456789012345678901234567890" is a valid number. 15 PASS "0.12345678901234567890123456789012345678901234567890" is a valid number. 16 PASS "abc" was sanitized to "". 17 PASS "0xff" was sanitized to "". 18 PASS "+1" was sanitized to "". 19 PASS " 10" was sanitized to "". 20 PASS "10 " was sanitized to "". 21 PASS "1,2" was sanitized to "". 22 PASS ".2" was sanitized to "". 23 PASS "1E" was sanitized to "". 24 PASS "NaN" was sanitized to "". 25 PASS "nan" was sanitized to "". 26 PASS "Inf" was sanitized to "". 27 PASS "inf" was sanitized to "". 28 PASS "Infinity" was sanitized to "". 29 PASS "infinity" was sanitized to "". 30 PASS "" is a valid number. 31 PASS "1.2E65535" was sanitized to "". 32 PASS "1." is a valid number. 33 PASS "1.2e10" is a valid number. 34 34 PASS successfullyParsed is true 35 35 -
trunk/LayoutTests/fast/forms/script-tests/ValidityState-typeMismatch-number.js
r48552 r67164 4 4 i.type = 'number'; 5 5 6 function check(value , mismatchExpected)6 function check(value) 7 7 { 8 8 i.value = value; 9 var actual = i.validity.typeMismatch; 10 var didPass = actual == mismatchExpected; 11 var resultText = value + ' is ' + (didPass ? 'a correct ' : 'an incorrect ') + (actual ? 'invalid' : 'valid') + ' number.'; 12 if (didPass) 9 var mismatch = i.validity.typeMismatch; 10 var resultText = '"' + value + '" is ' + (mismatch ? 'an invalid' : 'a valid') + ' number.'; 11 if (!mismatch) 13 12 testPassed(resultText); 14 13 else … … 16 15 } 17 16 17 function checkSanitization(value, expectedValue) 18 { 19 i.value = value; 20 if (i.validity.typeMismatch) { 21 testFailed('"' + value + '" made typeMismatch true.'); 22 } else if (i.value != expectedValue) { 23 testFailed('"' + value + '" was sanitized to "' + i.value + '". It should be ' + expectedValue); 24 } else { 25 testPassed('"' + value + '" was sanitized to "' + i.value + '".'); 26 } 27 } 28 18 29 // Valid values 19 check('0' , false);20 check('10' , false);21 check('01' , false);22 check('-0' , false);23 check('-1.2' , false);24 check('1.2E10' , false);25 check('1.2E-10' , false);26 check('1.2E+10' , false);27 check('12345678901234567890123456789012345678901234567890' , false);28 check('0.12345678901234567890123456789012345678901234567890' , false);30 check('0'); 31 check('10'); 32 check('01'); 33 check('-0'); 34 check('-1.2'); 35 check('1.2E10'); 36 check('1.2E-10'); 37 check('1.2E+10'); 38 check('12345678901234567890123456789012345678901234567890'); 39 check('0.12345678901234567890123456789012345678901234567890'); 29 40 30 41 // Invalid values 31 check ('abc', true);32 check ('0xff', true);42 checkSanitization('abc', ''); 43 checkSanitization('0xff', ''); 33 44 34 check ('+1', true);35 check (' 10', true);36 check ('10 ', true);37 check ('1,2', true);38 check ('.2', true);39 check ('1E', true);40 check ('NaN', true);41 check ('nan', true);42 check ('Inf', true);43 check ('inf', true);44 check ('Infinity', true);45 check ('infinity', true);45 checkSanitization('+1', ''); 46 checkSanitization(' 10', ''); 47 checkSanitization('10 ', ''); 48 checkSanitization('1,2', ''); 49 checkSanitization('.2', ''); 50 checkSanitization('1E', ''); 51 checkSanitization('NaN', ''); 52 checkSanitization('nan', ''); 53 checkSanitization('Inf', ''); 54 checkSanitization('inf', ''); 55 checkSanitization('Infinity', ''); 56 checkSanitization('infinity', ''); 46 57 47 58 // Assume empty string as valid. 48 check('' , false);59 check(''); 49 60 50 // The spec allows, but our implementation doesn't51 61 // Huge exponent. 52 check ('1.2E65535', true);62 checkSanitization('1.2E65535', ''); 53 63 54 64 // The spec doesn't allow, but our implementation does. 55 check('1.' , false);56 check('1.2e10' , false);65 check('1.'); 66 check('1.2e10'); 57 67 58 68 var successfullyParsed = true; -
trunk/WebCore/ChangeLog
r67163 r67164 1 2010-09-09 Kent Tamura <tkent@chromium.org> 2 3 Reviewed by Dimitri Glazkov. 4 5 <input type=number> should not have an invalid number as its value 6 https://bugs.webkit.org/show_bug.cgi?id=43973 7 8 This change implements the value sanitization algorithm for 9 type=number, and remove validity.typeMismatch support for 10 type=number in order to improve HTML5 conformance. 11 12 HTMLInputElement::value for type=number always has a valid number 13 string or an empty string. However, the input field for it, a 14 RenderTextControlSingleLine, can have a non-number string. For 15 example, '-' is a non-number string, but a user needs to type 16 '-'. So, the string in the input field has never been committed to 17 HTMLInputElement until the string becomes a valid number string. 18 19 This change is also a preparation of supporting localized 20 numbers. A localized string in the input field would not be 21 matched with HTMLInputElement::value. 22 23 Test: fast/forms/input-number-commit-valid-only.html 24 25 * dom/InputElement.h: Add isCommittableValue() 26 * html/HTMLInputElement.cpp: 27 (WebCore::HTMLInputElement::handleBlurEvent): 28 Set formControlValueMatchesRenderer false to clean an invalid value in the renderer. 29 (WebCore::HTMLInputElement::isCommittableValue): 30 (WebCore::HTMLInputElement::sanitizeValue): 31 * html/HTMLInputElement.h: 32 * html/ValidityState.cpp: 33 (WebCore::ValidityState::typeMismatch): Always returns false for type=number. 34 * rendering/RenderTextControlSingleLine.cpp: 35 (WebCore::RenderTextControlSingleLine::subtreeHasChanged): 36 * wml/WMLInputElement.h: 37 (WebCore::WMLInputElement::isCommittableValue): 38 1 39 2010-09-09 Tony Gentilcore <tonyg@chromium.org> 2 40 -
trunk/WebCore/dom/InputElement.h
r65335 r67164 61 61 virtual void setValueForUser(const String&) = 0; 62 62 63 // Returns true if the specified string can be set as the value of InputElement. 64 virtual bool isAcceptableValue(const String&) const = 0; 63 65 virtual String sanitizeValue(const String&) const = 0; 64 66 virtual void setValueFromRenderer(const String&) = 0; -
trunk/WebCore/html/HTMLInputElement.cpp
r67122 r67164 261 261 return !isValidColorString(value); 262 262 case NUMBER: 263 return !parseToDoubleForNumberType(value, 0); 263 ASSERT(parseToDoubleForNumberType(value, 0)); 264 return false; 264 265 case URL: 265 266 return !KURL(KURL(), value).isValid(); … … 828 829 void HTMLInputElement::handleBlurEvent() 829 830 { 831 // Reset the renderer value, which might be unmatched with the element value. 832 setFormControlValueMatchesRenderer(false); 830 833 InputElement::dispatchBlurEvent(this, this); 831 834 } … … 2665 2668 } 2666 2669 2670 bool HTMLInputElement::isAcceptableValue(const String& proposedValue) const 2671 { 2672 if (inputType() != NUMBER) 2673 return true; 2674 return proposedValue.isEmpty() || parseToDoubleForNumberType(proposedValue, 0); 2675 } 2676 2667 2677 String HTMLInputElement::sanitizeValue(const String& proposedValue) const 2668 2678 { 2679 if (inputType() == NUMBER) 2680 return parseToDoubleForNumberType(proposedValue, 0) ? proposedValue : String(); 2681 2669 2682 if (isTextField()) 2670 2683 return InputElement::sanitizeValueForTextField(this, proposedValue); -
trunk/WebCore/html/HTMLInputElement.h
r66357 r67164 282 282 virtual void cacheSelection(int start, int end); 283 283 284 virtual bool isAcceptableValue(const String&) const; 284 285 virtual String sanitizeValue(const String&) const; 285 286 -
trunk/WebCore/rendering/RenderTextControlSingleLine.cpp
r67122 r67164 171 171 // sanitizeUserInputValue(). 172 172 // sanitizeValue() is needed because IME input doesn't dispatch BeforeTextInsertedEvent. 173 input->setValueFromRenderer(input->sanitizeValue(text())); 173 String value = text(); 174 if (input->isAcceptableValue(value)) 175 input->setValueFromRenderer(input->sanitizeValue(value)); 174 176 175 177 if (m_cancelButton) -
trunk/WebCore/wml/WMLInputElement.h
r66362 r67164 83 83 virtual void cacheSelection(int start, int end); 84 84 85 virtual bool isAcceptableValue(const String&) const { return true; } 85 86 virtual String sanitizeValue(const String& proposedValue) const { return constrainValue(proposedValue); } 86 87
Note: See TracChangeset
for help on using the changeset viewer.