# HG changeset patch # Parent 4b5789932294d850b002b41a01564596dbcf54da # User Michael Shuen < mz_mhs-ctb@outlook.com> Bug 711180 - Ignore whitespace in atob; r=Ms2ger diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -658,17 +658,35 @@ nsresult nsContentUtils::Atob(const nsAString& aAsciiBase64String, nsAString& aBinaryData) { if (!Is8bit(aAsciiBase64String)) { aBinaryData.Truncate(); return NS_ERROR_DOM_INVALID_CHARACTER_ERR; } - nsresult rv = Base64Decode(aAsciiBase64String, aBinaryData); + const PRUnichar* start = aAsciiBase64String.BeginReading(); + const PRUnichar* iter = start; + const PRUnichar* end = aAsciiBase64String.EndReading(); + nsString trimmedString; + if (!trimmedString.SetCapacity(aAsciiBase64String.Length(), fallible_t())) { + return NS_ERROR_DOM_INVALID_CHARACTER_ERR; + } + bool needTrimming = false; + while (iter < end) { + if (!nsContentUtils::IsHTMLWhitespace(*iter)) { + if (!needTrimming) { + needTrimming = true; + trimmedString.Append(start, iter - start); + } + trimmedString.Append(*iter); + } + iter++; + } + nsresult rv = Base64Decode(trimmedString, aBinaryData); if (NS_FAILED(rv) && rv == NS_ERROR_INVALID_ARG) { return NS_ERROR_DOM_INVALID_CHARACTER_ERR; } return rv; } bool nsContentUtils::IsAutocompleteEnabled(nsIDOMHTMLInputElement* aInput) diff --git a/content/base/test/test_bug711180.html b/content/base/test/test_bug711180.html new file mode 100644 --- /dev/null +++ b/content/base/test/test_bug711180.html @@ -0,0 +1,25 @@ + + + +
++ ++ +