# HG changeset patch # Parent 4b5789932294d850b002b41a01564596dbcf54da # User Michael Shuen < mz_mhs-ctb@outlook.com> Atob should ignore whitespace - 711180 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,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/Makefile.in b/content/base/test/Makefile.in --- a/content/base/test/Makefile.in +++ b/content/base/test/Makefile.in @@ -238,16 +238,17 @@ MOCHITEST_FILES_A = \ test_domparser_null_char.html \ test_bug811701.html \ test_bug811701.xhtml \ test_bug820909.html \ test_bug704063.html \ test_bug894874.html \ test_bug895974.html \ test_bug895239.html \ + test_bug711180.html \ $(NULL) MOCHITEST_FILES_B = \ test_bug459424.html \ bug461735-redirect1.sjs \ bug461735-redirect2.sjs \ bug461735-post-redirect.js \ test_bug513194.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 @@ + + + +
++ ++ + 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 }