Bug 555711 - nsAttrValue::ParseNonNegativeIntValue should return PR_FALSE when the value is not valid, r=smaug

This commit is contained in:
mounir.lamouri@gmail.com 2010-04-11 17:12:51 +03:00
parent bfe7cc152d
commit 2a7d18aaa1
2 changed files with 4 additions and 7 deletions

View File

@ -1069,13 +1069,11 @@ nsAttrValue::ParseNonNegativeIntValue(const nsAString& aString)
PRInt32 ec;
PRBool strict;
PRInt32 originalVal = StringToInteger(aString, &strict, &ec);
if (NS_FAILED(ec)) {
if (NS_FAILED(ec) || originalVal < 0) {
return PR_FALSE;
}
PRInt32 val = PR_MAX(originalVal, -1);
strict = strict && (originalVal == val);
SetIntValueAndType(val, eInteger, strict ? nsnull : &aString);
SetIntValueAndType(originalVal, eInteger, nsnull);
return PR_TRUE;
}

View File

@ -244,10 +244,9 @@ public:
* Parse a string value into a non-negative integer.
* This method follows the rules for parsing non-negative integer from:
* http://dev.w3.org/html5/spec/infrastructure.html#rules-for-parsing-non-negative-integers
* If the parsed value is negative, the value will be set to -1.
*
* @param aString the string to parse
* @return whether the value could be parsed
* @param aString the string to parse
* @return whether the value is valid
*/
PRBool ParseNonNegativeIntValue(const nsAString& aString);