From 0b800bdc5025739b0608ea830cd80d860a03463d Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Mon, 17 Apr 2006 21:28:47 +0000 Subject: [PATCH] Don't trim whitespace off hidden input values. Bug 114997, patch by Steuard Jensen , r=sicking, sr=bzbarsky git-svn-id: svn://10.0.0.236/trunk@194535 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/html/content/src/nsHTMLInputElement.cpp | 9 +++++++++ mozilla/content/html/document/src/nsHTMLContentSink.cpp | 9 ++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/mozilla/content/html/content/src/nsHTMLInputElement.cpp b/mozilla/content/html/content/src/nsHTMLInputElement.cpp index 9dc5c117f4f..8ef76d0d5a6 100644 --- a/mozilla/content/html/content/src/nsHTMLInputElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLInputElement.cpp @@ -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; } diff --git a/mozilla/content/html/document/src/nsHTMLContentSink.cpp b/mozilla/content/html/document/src/nsHTMLContentSink.cpp index 3d35816d8a0..e047d330e82 100644 --- a/mozilla/content/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/content/html/document/src/nsHTMLContentSink.cpp @@ -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 : + // 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);