# HG changeset patch # Parent 51b36c5fd45fc39914478dd5c0175bbadf0a5a7f # User Michael Shuen < mz_mhs-ctb@outlook.com> Bug 711180 - Ignore whitespace in atob 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 @@ -661,17 +661,29 @@ 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* end = aAsciiBase64String.EndReading(); + nsString trimmedString; + if (!trimmedString.SetCapacity(aAsciiBase64String.Length(), fallible_t())) { + return NS_ERROR_DOM_INVALID_CHARACTER_ERR; + } + while (start < end) { + if (!nsContentUtils::IsHTMLWhitespace(*start)) { + trimmedString.Append(*start); + } + start++; + } + 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/mochitest.ini b/content/base/test/mochitest.ini --- a/content/base/test/mochitest.ini +++ b/content/base/test/mochitest.ini @@ -478,16 +478,17 @@ support-files = [test_bug698381.html] [test_bug698384.html] [test_bug702439.html] [test_bug702439.html^headers^] [test_bug704063.html] [test_bug707142.html] [test_bug708620.html] [test_bug711047.html] +[test_bug711180.html] [test_bug717511.html] [test_bug719533.html] [test_bug726364.html] [test_bug737087.html] [test_bug737565.html] [test_bug737612.html] [test_bug738108.html] [test_bug744830.html] 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 @@ + + + + + Test for Bug 711180 + + + + +Mozilla Bug 711180 +

+ +
+
+
+ + diff --git a/dom/imptests/failures/html/html/webappapis/atob/test_base64.html.json b/dom/imptests/failures/html/html/webappapis/atob/test_base64.html.json --- a/dom/imptests/failures/html/html/webappapis/atob/test_base64.html.json +++ b/dom/imptests/failures/html/html/webappapis/atob/test_base64.html.json @@ -1,14 +1,4 @@ { "btoa(null) == \"bnVsbA==\"": true, - "atob(\" abcd\") == \"i\u00b7\\x1d\"": true, - "atob(\"abcd \") == \"i\u00b7\\x1d\"": true, - "atob(\"ab\\tcd\") == \"i\u00b7\\x1d\"": true, - "atob(\"ab\\ncd\") == \"i\u00b7\\x1d\"": true, - "atob(\"ab\\fcd\") == \"i\u00b7\\x1d\"": true, - "atob(\"ab\\rcd\") == \"i\u00b7\\x1d\"": true, - "atob(\"ab cd\") == \"i\u00b7\\x1d\"": true, - "atob(\"ab\\t\\n\\f\\r cd\") == \"i\u00b7\\x1d\"": true, - "atob(\" \\t\\n\\f\\r ab\\t\\n\\f\\r cd\\t\\n\\f\\r \") == \"i\u00b7\\x1d\"": true, - "atob(\"ab\\t\\n\\f\\r =\\t\\n\\f\\r =\\t\\n\\f\\r \") == \"i\"": true, "atob(null) == \"\u009e\u00e9e\"": true }