Don't trim whitespace off hidden input values. Bug 114997, patch by Steuard

Jensen <steuard+moz@slimy.com>, r=sicking, sr=bzbarsky
This commit is contained in:
bzbarsky%mit.edu 2006-04-17 21:28:47 +00:00
parent 9d31bba6bc
commit ff35061446
2 changed files with 17 additions and 1 deletions

View File

@ -603,6 +603,8 @@ nsHTMLInputElement::SetSize(PRUint32 aValue)
NS_IMETHODIMP
nsHTMLInputElement::GetValue(nsAString& aValue)
{
static const char* kWhitespace = "\n\r\t\b";
if (mType == NS_FORM_INPUT_TEXT || mType == NS_FORM_INPUT_PASSWORD ||
mType == NS_FORM_INPUT_FILE) {
// No need to flush here, if there's no frame created for this
@ -631,6 +633,9 @@ nsHTMLInputElement::GetValue(nsAString& aValue)
} else {
CopyUTF8toUTF16(mValue, aValue);
}
// Bug 114997: trim \n, etc. for non-hidden inputs
aValue = nsContentUtils::TrimCharsInSet(kWhitespace, aValue);
}
return NS_OK;
@ -643,6 +648,10 @@ nsHTMLInputElement::GetValue(nsAString& aValue)
aValue.AssignLiteral("on");
}
if (mType != NS_FORM_INPUT_HIDDEN) {
aValue = nsContentUtils::TrimCharsInSet(kWhitespace, aValue);
}
return NS_OK;
}

View File

@ -839,8 +839,15 @@ HTMLContentSink::AddAttributes(const nsIParserNode& aNode,
// Get value and remove mandatory quotes
static const char* kWhitespace = "\n\r\t\b";
// Bug 114997: Don't trim whitespace on <input value="...">:
// Using ?: outside the function call would be more efficient, but
// we don't trust ?: with references.
const nsAString& v =
nsContentUtils::TrimCharsInSet(kWhitespace, aNode.GetValueAt(i));
nsContentUtils::TrimCharsInSet(
(nodeType == eHTMLTag_input &&
keyAtom == nsHTMLAtoms::value) ?
"" : kWhitespace, aNode.GetValueAt(i));
if (nodeType == eHTMLTag_a && keyAtom == nsHTMLAtoms::name) {
NS_ConvertUTF16toUTF8 cname(v);