diff --git a/content/base/src/nsAttrValue.cpp b/content/base/src/nsAttrValue.cpp
index 4525b396865d..91791576fd6f 100644
--- a/content/base/src/nsAttrValue.cpp
+++ b/content/base/src/nsAttrValue.cpp
@@ -1356,70 +1356,70 @@ nsAttrValue::StringToInteger(const nsAString& aValue, bool* aStrict,
bool aCanBePercent,
bool* aIsPercent) const
{
- *aStrict = PR_FALSE;
+ *aStrict = true;
*aErrorCode = NS_ERROR_ILLEGAL_VALUE;
if (aCanBePercent) {
- *aIsPercent = PR_FALSE;
+ *aIsPercent = false;
}
nsAString::const_iterator iter, end;
aValue.BeginReading(iter);
aValue.EndReading(end);
+
+ while (iter != end && nsContentUtils::IsHTMLWhitespace(*iter)) {
+ *aStrict = false;
+ ++iter;
+ }
+
+ if (iter == end) {
+ return 0;
+ }
+
bool negate = false;
+ if (*iter == PRUnichar('-')) {
+ negate = true;
+ ++iter;
+ } else if (*iter == PRUnichar('+')) {
+ *aStrict = false;
+ ++iter;
+ }
+
PRInt32 value = 0;
- if (iter != end) {
- if (*iter == PRUnichar('-')) {
- negate = PR_TRUE;
+ PRInt32 pValue = 0; // Previous value, used to check integer overflow
+ while (iter != end) {
+ if (*iter >= PRUnichar('0') && *iter <= PRUnichar('9')) {
+ value = (value * 10) + (*iter - PRUnichar('0'));
++iter;
- }
- if (iter != end) {
- if ((*iter >= PRUnichar('1') || (*iter == PRUnichar('0') && !negate)) &&
- *iter <= PRUnichar('9')) {
- value = *iter - PRUnichar('0');
- ++iter;
- *aStrict = (value != 0 || iter == end ||
- (aCanBePercent && *iter == PRUnichar('%')));
- while (iter != end && *aStrict) {
- if (*iter >= PRUnichar('0') && *iter <= PRUnichar('9')) {
- value = (value * 10) + (*iter - PRUnichar('0'));
- ++iter;
- if (iter != end && value > ((PR_INT32_MAX / 10) - 9)) {
- *aStrict = PR_FALSE;
- }
- } else if (aCanBePercent && *iter == PRUnichar('%')) {
- ++iter;
- if (iter == end) {
- *aIsPercent = PR_TRUE;
- } else {
- *aStrict = PR_FALSE;
- }
- } else {
- *aStrict = PR_FALSE;
- }
- }
- if (*aStrict) {
- if (negate) {
- value = -value;
- }
- if (!aCanBePercent || !*aIsPercent) {
- *aErrorCode = NS_OK;
-#ifdef DEBUG
- nsAutoString stringValue;
- stringValue.AppendInt(value);
- if (aCanBePercent && *aIsPercent) {
- stringValue.AppendLiteral("%");
- }
- NS_ASSERTION(stringValue.Equals(aValue), "Wrong conversion!");
-#endif
- return value;
- }
- }
+ // Checking for integer overflow.
+ if (pValue > value) {
+ *aStrict = false;
+ *aErrorCode = NS_ERROR_ILLEGAL_VALUE;
+ break;
+ } else {
+ pValue = value;
+ *aErrorCode = NS_OK;
}
+ } else if (aCanBePercent && *iter == PRUnichar('%')) {
+ ++iter;
+ *aIsPercent = true;
+ if (iter != end) {
+ *aStrict = false;
+ break;
+ }
+ } else {
+ *aStrict = false;
+ break;
+ }
+ }
+ if (negate) {
+ value = -value;
+ // Checking the special case of -0.
+ if (!value) {
+ *aStrict = false;
}
}
- nsAutoString tmp(aValue);
- return tmp.ToInteger(aErrorCode);
+ return value;
}
PRInt64
diff --git a/content/canvas/test/test_canvas.html b/content/canvas/test/test_canvas.html
index f04613b873ce..61cbea01de2f 100644
--- a/content/canvas/test/test_canvas.html
+++ b/content/canvas/test/test_canvas.html
@@ -20190,7 +20190,7 @@ function test_size_attributes_parse_badsuffix() {
var canvas = document.getElementById('c637');
var ctx = canvas.getContext('2d');
-todo(canvas.width == 100, "canvas.width == 100");
+is(canvas.width, 100, "canvas.width == 100");
}
@@ -20400,7 +20400,7 @@ var canvas = document.getElementById('c648');
var ctx = canvas.getContext('2d');
canvas.setAttribute('width', '100foo');
-todo(canvas.width == 100, "canvas.width == 100");
+is(canvas.width, 100, "canvas.width == 100");
}
diff --git a/content/html/content/test/reflect.js b/content/html/content/test/reflect.js
index 53fa8458cac8..4b019db982a2 100644
--- a/content/html/content/test/reflect.js
+++ b/content/html/content/test/reflect.js
@@ -462,11 +462,6 @@ function reflectBoolean(aParameters)
*/
function reflectInt(aParameters)
{
- //TBD: Bug 673820: .setAttribute(exponential) -> incorrect reflection for element[attr]
- function testExponential(value) {
- return !!/^[ \t\n\f\r]*[\+\-]?[0-9]+e[0-9]+/.exec(value);
- }
-
// Expected value returned by .getAttribute() when |value| has been previously passed to .setAttribute().
function expectedGetAttributeResult(value) {
return (value !== null) ? String(value) : "";
@@ -556,34 +551,10 @@ function reflectInt(aParameters)
//TBD: Bug 586761: .setAttribute(attr, -2147483648) --> element[attr] == defaultValue instead of -2147483648
todo_is(element[attr], intValue, "Bug 586761: " + element.localName +
".setAttribute(value, " + v + "), " + element.localName + "[" + attr + "] ");
- } else if (testExponential(v)) {
- //TBD: Bug 673820: .setAttribute(exponential) -> incorrect reflection for element[attr]
- todo_is(element[attr], intValue, "Bug 673820: " + element.localName +
- ".setAttribute(" + attr + ", " + v + "), " + element.localName + "[" + attr + "] ");
- } else if (v == "why 567 what") {
- //TBD: Bug 679672: .setAttribute() is somehow able to parse "why 567 what" into "567"
- todo_is(element[attr], intValue, "Bug 679672: " + element.localName +
- ".setAttribute(" + attr + ", " + v + "), " + element.localName + "[" + attr + "] ");
- } else if (v === "-0" && nonNegative) {
+ } else if ((v === "-0" || v == "-0xABCDEF") && nonNegative) {
//TBD: Bug 688093: Non-negative integers should return defaultValue when attempting to reflect "-0"
todo_is(element[attr], intValue, "Bug 688093: " + element.localName +
".setAttribute(" + attr + ", " + v + "), " + element.localName + "[" + attr + "] ");
- } else if (v == "+42foo") {
- //TBD: Bug: Unable to correctly parse "+" character in front of string
- todo_is(element[attr], intValue, "Bug: " + element.localName +
- ".setAttribute(" + attr + ", " + v + "), " + element.localName + "[" + attr + "] ");
- } else if (v == "0x10FFFF" && defaultValue != 0) {
- //TBD: Bug: Integer attributes should parse "0x10FFFF" as 0, but instead incorrectly return defaultValue
- todo_is(element[attr], intValue, "Bug: " + element.localName +
- ".setAttribute(" + attr + ", " + v + "), " + element.localName + "[" + attr + "] ");
- } else if (v == "-0xABCDEF" && !nonNegative && defaultValue != 0) {
- //TBD: Bug: Signed integer attributes should parse "-0xABCDEF" as -0, but instead incorrectly return defaultValue
- todo_is(element[attr], intValue, "Bug: " + element.localName +
- ".setAttribute(" + attr + ", " + v + "), " + element.localName + "[" + attr + "] ");
- } else if ((v == "++2" || v == "+-2" || v == "--2" || v == "-+2") && element[attr] != defaultValue) {
- //TBD: Bug: Should not be able to parse strings with multiple sign characters, should return defaultValue
- todo_is(element[attr], intValue, "Bug: " + element.localName +
- ".setAttribute(" + attr + ", " + v + "), " + element.localName + "[" + attr + "] ");
} else {
is(element[attr], intValue, element.localName +
".setAttribute(" + attr + ", " + v + "), " + element.localName + "[" + attr + "] ");
diff --git a/layout/reftests/bugs/539880-1-ref.html b/layout/reftests/bugs/539880-1-ref.html
index 853b0a94a489..8f8a8ac9477c 100644
--- a/layout/reftests/bugs/539880-1-ref.html
+++ b/layout/reftests/bugs/539880-1-ref.html
@@ -6,7 +6,7 @@
0 |
|
|
- |
+ |
1 |
@@ -18,19 +18,19 @@
2 |
|
|
- |
+ |
3 |
|
|
- |
+ |
10 |
|
|
- |
+ |