Bug 711180 - Ignore whitespace in atob. r=Ms2ger

This commit is contained in:
Michael Shuen 2013-09-10 21:10:46 -04:00
parent d77b0369a3
commit f79fad7a30
2 changed files with 44 additions and 1 deletions

View File

@ -665,7 +665,25 @@ nsContentUtils::Atob(const nsAString& aAsciiBase64String,
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;
}

View File

@ -0,0 +1,25 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=711180
-->
<head>
<title>Test for Bug 711180</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=711180">Mozilla Bug 711180</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 711180 **/
is(atob("aQ=="), atob("\t a\rQ\n=\f="), "Base64 space removal");
</script>
</pre>
</body>
</html>