Diff
Modified: trunk/LayoutTests/ChangeLog (195693 => 195694)
--- trunk/LayoutTests/ChangeLog 2016-01-27 22:31:17 UTC (rev 195693)
+++ trunk/LayoutTests/ChangeLog 2016-01-27 22:37:48 UTC (rev 195694)
@@ -1,3 +1,17 @@
+2016-01-27 Chris Dumez <[email protected]>
+
+ window.atob() should ignore spaces in input
+ https://bugs.webkit.org/show_bug.cgi?id=153522
+ <rdar://problem/24357822>
+
+ Reviewed by Benjamin Poulain.
+
+ Update window.atob() test to cover cases with spaces in
+ input.
+
+ * fast/dom/Window/atob-btoa-expected.txt:
+ * fast/dom/Window/atob-btoa.html:
+
2016-01-27 Brady Eidson <[email protected]>
Modern IDB: SQLite backend doesn't update index records as object records are added.
Modified: trunk/LayoutTests/fast/dom/Window/atob-btoa-expected.txt (195693 => 195694)
--- trunk/LayoutTests/fast/dom/Window/atob-btoa-expected.txt 2016-01-27 22:31:17 UTC (rev 195693)
+++ trunk/LayoutTests/fast/dom/Window/atob-btoa-expected.txt 2016-01-27 22:37:48 UTC (rev 195694)
@@ -26,8 +26,19 @@
PASS window.atob("") is ""
PASS window.atob(null) is "ée"
PASS window.atob(undefined) threw exception Error: InvalidCharacterError: DOM Exception 5.
-PASS window.atob(" YQ==") threw exception Error: InvalidCharacterError: DOM Exception 5.
-PASS window.atob("YQ==\u000a") threw exception Error: InvalidCharacterError: DOM Exception 5.
+PASS window.atob(" YQ==") is "a"
+PASS window.atob("YQ==\u000a") is "a"
+PASS window.atob("ab\tcd") is "i·"
+PASS window.atob("ab\ncd") is "i·"
+PASS window.atob("ab\fcd") is "i·"
+PASS window.atob("ab cd") is "i·"
+PASS window.atob("ab\t\n\f\r cd") is "i·"
+PASS window.atob(" \t\n\f\r ab\t\n\f\r cd\t\n\f\r ") is "i·"
+PASS window.atob("ab\t\n\f\r =\t\n\f\r =\t\n\f\r ") is "i"
+PASS window.atob(" ") is ""
+PASS window.atob(" abcd===") threw exception Error: InvalidCharacterError: DOM Exception 5.
+PASS window.atob("abcd=== ") threw exception Error: InvalidCharacterError: DOM Exception 5.
+PASS window.atob("abcd ===") threw exception Error: InvalidCharacterError: DOM Exception 5.
PASS window.atob("6ek=") is "éé"
PASS window.atob("6ek") is "éé"
PASS window.atob("gIE=") is ""
Modified: trunk/LayoutTests/fast/dom/Window/atob-btoa.html (195693 => 195694)
--- trunk/LayoutTests/fast/dom/Window/atob-btoa.html 2016-01-27 22:31:17 UTC (rev 195693)
+++ trunk/LayoutTests/fast/dom/Window/atob-btoa.html 2016-01-27 22:37:48 UTC (rev 195694)
@@ -36,8 +36,19 @@
shouldBe('window.atob("")', '""');
shouldBe('window.atob(null)', '"\x9Eée"'); // Gets converted to "null" string.
shouldThrow('window.atob(undefined)');
-shouldThrow('window.atob(" YQ==")');
-shouldThrow('window.atob("YQ==\\u000a")');
+shouldBe('window.atob(" YQ==")', '"a"');
+shouldBe('window.atob("YQ==\\u000a")', '"a"');
+shouldBe('window.atob("ab\\tcd")', '"i·\x1d"');
+shouldBe('window.atob("ab\\ncd")', '"i·\x1d"');
+shouldBe('window.atob("ab\\fcd")', '"i·\x1d"');
+shouldBe('window.atob("ab cd")', '"i·\x1d"');
+shouldBe('window.atob("ab\\t\\n\\f\\r cd")', '"i·\x1d"');
+shouldBe('window.atob(" \\t\\n\\f\\r ab\\t\\n\\f\\r cd\\t\\n\\f\\r ")', '"i·\x1d"');
+shouldBe('window.atob("ab\\t\\n\\f\\r =\\t\\n\\f\\r =\\t\\n\\f\\r ")', '"i"');
+shouldBe('window.atob(" ")', '""');
+shouldThrow('window.atob(" abcd===")');
+shouldThrow('window.atob("abcd=== ")');
+shouldThrow('window.atob("abcd ===")');
shouldBe('window.atob("6ek=")', '"éé"');
shouldBe('window.atob("6ek")', '"éé"');
shouldBe('window.atob("gIE=")', '"\u0080\u0081"');
Modified: trunk/Source/WTF/ChangeLog (195693 => 195694)
--- trunk/Source/WTF/ChangeLog 2016-01-27 22:31:17 UTC (rev 195693)
+++ trunk/Source/WTF/ChangeLog 2016-01-27 22:37:48 UTC (rev 195694)
@@ -1,3 +1,23 @@
+2016-01-27 Chris Dumez <[email protected]>
+
+ window.atob() should ignore spaces in input
+ https://bugs.webkit.org/show_bug.cgi?id=153522
+ <rdar://problem/24357822>
+
+ Reviewed by Benjamin Poulain.
+
+ Turn Base64DecodePolicy enum into flags so that the caller can indicate
+ to both validate padding AND ignore spaces.
+
+ Also make sure that the output Vector size is properly shrunk when
+ spaces are ignored.
+
+ * wtf/text/Base64.cpp:
+ (WTF::base64DecodeInternal):
+ (WTF::base64Decode):
+ (WTF::base64URLDecode):
+ * wtf/text/Base64.h:
+
2016-01-27 Alexey Proskuryakov <[email protected]>
Remove ENABLE_CURRENTSRC
Modified: trunk/Source/WTF/wtf/text/Base64.cpp (195693 => 195694)
--- trunk/Source/WTF/wtf/text/Base64.cpp 2016-01-27 22:31:17 UTC (rev 195693)
+++ trunk/Source/WTF/wtf/text/Base64.cpp 2016-01-27 22:37:48 UTC (rev 195694)
@@ -1,7 +1,7 @@
/*
Copyright (C) 2000-2001 Dawit Alemayehu <[email protected]>
Copyright (C) 2006 Alexey Proskuryakov <[email protected]>
- Copyright (C) 2007, 2008, 2013 Apple Inc. All rights reserved.
+ Copyright (C) 2007, 2008, 2013, 2016 Apple Inc. All rights reserved.
Copyright (C) 2010 Patrick Gansterer <[email protected]>
This program is free software; you can redistribute it and/or modify
@@ -182,7 +182,7 @@
}
template<typename T>
-static inline bool base64DecodeInternal(const T* data, unsigned length, Vector<char>& out, Base64DecodePolicy policy, const char (&decodeMap)[128])
+static inline bool base64DecodeInternal(const T* data, unsigned length, Vector<char>& out, unsigned options, const char (&decodeMap)[128])
{
out.clear();
if (!length)
@@ -192,29 +192,47 @@
unsigned equalsSignCount = 0;
unsigned outLength = 0;
+ bool hadError = false;
for (unsigned idx = 0; idx < length; ++idx) {
unsigned ch = data[idx];
if (ch == '=') {
++equalsSignCount;
- // There should be no padding if length is a multiple of 4, and there
- // should never be more than 2 padding characters.
- if (policy == Base64FailOnInvalidCharacterOrExcessPadding && (length % 4 || equalsSignCount > 2))
- return false;
+ // There should never be more than 2 padding characters.
+ if (options & Base64ValidatePadding && equalsSignCount > 2) {
+ hadError = true;
+ break;
+ }
} else {
char decodedCharacter = ch < WTF_ARRAY_LENGTH(decodeMap) ? decodeMap[ch] : nonAlphabet;
if (decodedCharacter != nonAlphabet) {
- if (equalsSignCount)
- return false;
- out[outLength] = decodedCharacter;
- ++outLength;
- } else if (policy == Base64FailOnInvalidCharacterOrExcessPadding || policy == Base64FailOnInvalidCharacter || (policy == Base64IgnoreWhitespace && !isSpaceOrNewline(ch)))
- return false;
+ if (equalsSignCount) {
+ hadError = true;
+ break;
+ }
+ out[outLength++] = decodedCharacter;
+ } else if (!(options & Base64IgnoreSpacesAndNewLines) || !isSpaceOrNewline(ch)) {
+ hadError = true;
+ break;
+ }
}
}
+ // Make sure we shrink back the Vector before returning. outLength may be shorter than expected
+ // in case of error or in case of ignored spaces.
+ if (outLength < out.size())
+ out.shrink(outLength);
+
+ if (hadError)
+ return false;
+
if (!outLength)
return !equalsSignCount;
+ // The should be no padding if length is a multiple of 4.
+ // We use (outLength + equalsSignCount) instead of length because we don't want to account for ignored characters (i.e. spaces).
+ if (options & Base64ValidatePadding && equalsSignCount && (outLength + equalsSignCount) % 4)
+ return false;
+
// Valid data is (n * 4 + [0,2,3]) characters long.
if ((outLength % 4) == 1)
return false;
@@ -248,15 +266,15 @@
return true;
}
-bool base64Decode(const String& in, SignedOrUnsignedCharVectorAdapter out, Base64DecodePolicy policy)
+bool base64Decode(const String& in, SignedOrUnsignedCharVectorAdapter out, unsigned options)
{
unsigned length = in.length();
if (!length || in.is8Bit())
- return base64DecodeInternal(in.characters8(), length, out, policy, base64DecMap);
- return base64DecodeInternal(in.characters16(), length, out, policy, base64DecMap);
+ return base64DecodeInternal(in.characters8(), length, out, options, base64DecMap);
+ return base64DecodeInternal(in.characters16(), length, out, options, base64DecMap);
}
-bool base64Decode(const Vector<char>& in, SignedOrUnsignedCharVectorAdapter out, Base64DecodePolicy policy)
+bool base64Decode(const Vector<char>& in, SignedOrUnsignedCharVectorAdapter out, unsigned options)
{
out.clear();
@@ -264,20 +282,20 @@
if (in.size() > UINT_MAX)
return false;
- return base64DecodeInternal(reinterpret_cast<const LChar*>(in.data()), in.size(), out, policy, base64DecMap);
+ return base64DecodeInternal(reinterpret_cast<const LChar*>(in.data()), in.size(), out, options, base64DecMap);
}
-bool base64Decode(const char* data, unsigned len, SignedOrUnsignedCharVectorAdapter out, Base64DecodePolicy policy)
+bool base64Decode(const char* data, unsigned len, SignedOrUnsignedCharVectorAdapter out, unsigned options)
{
- return base64DecodeInternal(reinterpret_cast<const LChar*>(data), len, out, policy, base64DecMap);
+ return base64DecodeInternal(reinterpret_cast<const LChar*>(data), len, out, options, base64DecMap);
}
bool base64URLDecode(const String& in, SignedOrUnsignedCharVectorAdapter out)
{
unsigned length = in.length();
if (!length || in.is8Bit())
- return base64DecodeInternal(in.characters8(), length, out, Base64FailOnInvalidCharacter, base64URLDecMap);
- return base64DecodeInternal(in.characters16(), length, out, Base64FailOnInvalidCharacter, base64URLDecMap);
+ return base64DecodeInternal(in.characters8(), length, out, Base64Default, base64URLDecMap);
+ return base64DecodeInternal(in.characters16(), length, out, Base64Default, base64URLDecMap);
}
bool base64URLDecode(const Vector<char>& in, SignedOrUnsignedCharVectorAdapter out)
@@ -288,12 +306,12 @@
if (in.size() > UINT_MAX)
return false;
- return base64DecodeInternal(reinterpret_cast<const LChar*>(in.data()), in.size(), out, Base64FailOnInvalidCharacter, base64URLDecMap);
+ return base64DecodeInternal(reinterpret_cast<const LChar*>(in.data()), in.size(), out, Base64Default, base64URLDecMap);
}
bool base64URLDecode(const char* data, unsigned len, SignedOrUnsignedCharVectorAdapter out)
{
- return base64DecodeInternal(reinterpret_cast<const LChar*>(data), len, out, Base64FailOnInvalidCharacter, base64URLDecMap);
+ return base64DecodeInternal(reinterpret_cast<const LChar*>(data), len, out, Base64Default, base64URLDecMap);
}
} // namespace WTF
Modified: trunk/Source/WTF/wtf/text/Base64.h (195693 => 195694)
--- trunk/Source/WTF/wtf/text/Base64.h 2016-01-27 22:31:17 UTC (rev 195693)
+++ trunk/Source/WTF/wtf/text/Base64.h 2016-01-27 22:37:48 UTC (rev 195694)
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2006 Alexey Proskuryakov <[email protected]>
* Copyright (C) 2010 Patrick Gansterer <[email protected]>
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013, 2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -40,11 +40,10 @@
Base64URLPolicy // No padding, no LFs.
};
-enum Base64DecodePolicy {
- Base64FailOnInvalidCharacterOrExcessPadding,
- Base64FailOnInvalidCharacter,
- Base64IgnoreWhitespace,
- Base64IgnoreInvalidCharacters
+enum Base64DecodeOptions {
+ Base64Default = 0,
+ Base64ValidatePadding = 1 << 0,
+ Base64IgnoreSpacesAndNewLines = 1 << 1,
};
class SignedOrUnsignedCharVectorAdapter {
@@ -85,9 +84,9 @@
String base64Encode(ConstSignedOrUnsignedCharVectorAdapter, Base64EncodePolicy = Base64DoNotInsertLFs);
String base64Encode(const CString&, Base64EncodePolicy = Base64DoNotInsertLFs);
-WTF_EXPORT_PRIVATE bool base64Decode(const String&, SignedOrUnsignedCharVectorAdapter, Base64DecodePolicy = Base64FailOnInvalidCharacter);
-WTF_EXPORT_PRIVATE bool base64Decode(const Vector<char>&, SignedOrUnsignedCharVectorAdapter, Base64DecodePolicy = Base64FailOnInvalidCharacter);
-WTF_EXPORT_PRIVATE bool base64Decode(const char*, unsigned, SignedOrUnsignedCharVectorAdapter, Base64DecodePolicy = Base64FailOnInvalidCharacter);
+WTF_EXPORT_PRIVATE bool base64Decode(const String&, SignedOrUnsignedCharVectorAdapter, unsigned options = Base64Default);
+WTF_EXPORT_PRIVATE bool base64Decode(const Vector<char>&, SignedOrUnsignedCharVectorAdapter, unsigned options = Base64Default);
+WTF_EXPORT_PRIVATE bool base64Decode(const char*, unsigned, SignedOrUnsignedCharVectorAdapter, unsigned options = Base64Default);
inline void base64Encode(ConstSignedOrUnsignedCharVectorAdapter in, Vector<char>& out, Base64EncodePolicy policy)
{
@@ -151,11 +150,8 @@
using WTF::Base64EncodePolicy;
using WTF::Base64DoNotInsertLFs;
using WTF::Base64InsertLFs;
-using WTF::Base64DecodePolicy;
-using WTF::Base64FailOnInvalidCharacterOrExcessPadding;
-using WTF::Base64FailOnInvalidCharacter;
-using WTF::Base64IgnoreWhitespace;
-using WTF::Base64IgnoreInvalidCharacters;
+using WTF::Base64ValidatePadding;
+using WTF::Base64IgnoreSpacesAndNewLines;
using WTF::base64Encode;
using WTF::base64Decode;
using WTF::base64URLDecode;
Modified: trunk/Source/WebCore/ChangeLog (195693 => 195694)
--- trunk/Source/WebCore/ChangeLog 2016-01-27 22:31:17 UTC (rev 195693)
+++ trunk/Source/WebCore/ChangeLog 2016-01-27 22:37:48 UTC (rev 195694)
@@ -1,3 +1,31 @@
+2016-01-27 Chris Dumez <[email protected]>
+
+ window.atob() should ignore spaces in input
+ https://bugs.webkit.org/show_bug.cgi?id=153522
+ <rdar://problem/24357822>
+
+ Reviewed by Benjamin Poulain.
+
+ window.atob() should ignore spaces in input as per:
+ - https://html.spec.whatwg.org/#dom-windowbase64-atob (Step 3)
+
+ Previously, WebKit would throw an exception and it was the only browser
+ to do so. Firefox and Chrome behavior according to the specification.
+
+ This was causing us to fail 10 checks in the following W3C HTML test:
+ http://w3c-test.org/html/webappapis/atob/base64.html
+
+ No new tests, updated existing test.
+
+ * page/DOMWindow.cpp:
+ (WebCore::DOMWindow::atob):
+ * page/Page.cpp:
+ (WebCore::Page::userStyleSheetLocationChanged):
+ * platform/network/DataURL.cpp:
+ (WebCore::handleDataURL):
+ * platform/network/DataURLDecoder.cpp:
+ (WebCore::DataURLDecoder::decodeBase64):
+
2016-01-27 Ada Chan <[email protected]>
Move some logic related to the presentation mode button from mediaControlsiOS.js to mediaControlsApple.js
Modified: trunk/Source/WebCore/page/DOMWindow.cpp (195693 => 195694)
--- trunk/Source/WebCore/page/DOMWindow.cpp 2016-01-27 22:31:17 UTC (rev 195693)
+++ trunk/Source/WebCore/page/DOMWindow.cpp 2016-01-27 22:37:48 UTC (rev 195694)
@@ -1160,7 +1160,7 @@
}
Vector<char> out;
- if (!base64Decode(encodedString, out, Base64FailOnInvalidCharacterOrExcessPadding)) {
+ if (!base64Decode(encodedString, out, Base64ValidatePadding | Base64IgnoreSpacesAndNewLines)) {
ec = INVALID_CHARACTER_ERR;
return String();
}
Modified: trunk/Source/WebCore/page/Page.cpp (195693 => 195694)
--- trunk/Source/WebCore/page/Page.cpp 2016-01-27 22:31:17 UTC (rev 195693)
+++ trunk/Source/WebCore/page/Page.cpp 2016-01-27 22:37:48 UTC (rev 195694)
@@ -1032,7 +1032,7 @@
m_didLoadUserStyleSheet = true;
Vector<char> styleSheetAsUTF8;
- if (base64Decode(decodeURLEscapeSequences(url.string().substring(35)), styleSheetAsUTF8, Base64IgnoreWhitespace))
+ if (base64Decode(decodeURLEscapeSequences(url.string().substring(35)), styleSheetAsUTF8, Base64IgnoreSpacesAndNewLines))
m_userStyleSheet = String::fromUTF8(styleSheetAsUTF8.data(), styleSheetAsUTF8.size());
}
Modified: trunk/Source/WebCore/platform/network/DataURL.cpp (195693 => 195694)
--- trunk/Source/WebCore/platform/network/DataURL.cpp 2016-01-27 22:31:17 UTC (rev 195693)
+++ trunk/Source/WebCore/platform/network/DataURL.cpp 2016-01-27 22:37:48 UTC (rev 195694)
@@ -76,7 +76,7 @@
handle->client()->didReceiveResponse(handle, response);
Vector<char> out;
- if (base64Decode(data, out, Base64IgnoreWhitespace) && out.size() > 0) {
+ if (base64Decode(data, out, Base64IgnoreSpacesAndNewLines) && out.size() > 0) {
response.setExpectedContentLength(out.size());
handle->client()->didReceiveData(handle, out.data(), out.size(), 0);
}
Modified: trunk/Source/WebCore/platform/network/DataURLDecoder.cpp (195693 => 195694)
--- trunk/Source/WebCore/platform/network/DataURLDecoder.cpp 2016-01-27 22:31:17 UTC (rev 195693)
+++ trunk/Source/WebCore/platform/network/DataURLDecoder.cpp 2016-01-27 22:37:48 UTC (rev 195694)
@@ -144,7 +144,7 @@
if (!base64URLDecode(task.encodedData.toStringWithoutCopying(), buffer)) {
// Didn't work, try unescaping and decoding as base64.
auto unescapedString = decodeURLEscapeSequences(task.encodedData.toStringWithoutCopying());
- if (!base64Decode(unescapedString, buffer, Base64IgnoreWhitespace))
+ if (!base64Decode(unescapedString, buffer, Base64IgnoreSpacesAndNewLines))
return;
}
buffer.shrinkToFit();
Modified: trunk/Source/WebKit/mac/ChangeLog (195693 => 195694)
--- trunk/Source/WebKit/mac/ChangeLog 2016-01-27 22:31:17 UTC (rev 195693)
+++ trunk/Source/WebKit/mac/ChangeLog 2016-01-27 22:37:48 UTC (rev 195694)
@@ -1,3 +1,14 @@
+2016-01-27 Chris Dumez <[email protected]>
+
+ window.atob() should ignore spaces in input
+ https://bugs.webkit.org/show_bug.cgi?id=153522
+ <rdar://problem/24357822>
+
+ Reviewed by Benjamin Poulain.
+
+ * WebCoreSupport/WebInspectorClient.mm:
+ (WebInspectorFrontendClient::save):
+
2016-01-27 Alexey Proskuryakov <[email protected]>
Remove ENABLE_CURRENTSRC
Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebInspectorClient.mm (195693 => 195694)
--- trunk/Source/WebKit/mac/WebCoreSupport/WebInspectorClient.mm 2016-01-27 22:31:17 UTC (rev 195693)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebInspectorClient.mm 2016-01-27 22:37:48 UTC (rev 195694)
@@ -310,7 +310,7 @@
if (base64Encoded) {
Vector<char> out;
- if (!base64Decode(contentCopy, out, Base64FailOnInvalidCharacterOrExcessPadding))
+ if (!base64Decode(contentCopy, out, Base64ValidatePadding))
return;
RetainPtr<NSData> dataContent = adoptNS([[NSData alloc] initWithBytes:out.data() length:out.size()]);
[dataContent writeToURL:actualURL atomically:YES];
Modified: trunk/Source/WebKit2/ChangeLog (195693 => 195694)
--- trunk/Source/WebKit2/ChangeLog 2016-01-27 22:31:17 UTC (rev 195693)
+++ trunk/Source/WebKit2/ChangeLog 2016-01-27 22:37:48 UTC (rev 195694)
@@ -1,3 +1,14 @@
+2016-01-27 Chris Dumez <[email protected]>
+
+ window.atob() should ignore spaces in input
+ https://bugs.webkit.org/show_bug.cgi?id=153522
+ <rdar://problem/24357822>
+
+ Reviewed by Benjamin Poulain.
+
+ * UIProcess/mac/WebInspectorProxyMac.mm:
+ (WebKit::WebInspectorProxy::platformSave):
+
2016-01-27 Ryosuke Niwa <[email protected]>
Add API to access closed shadowRoot in InjectedBundle
Modified: trunk/Source/WebKit2/UIProcess/mac/WebInspectorProxyMac.mm (195693 => 195694)
--- trunk/Source/WebKit2/UIProcess/mac/WebInspectorProxyMac.mm 2016-01-27 22:31:17 UTC (rev 195693)
+++ trunk/Source/WebKit2/UIProcess/mac/WebInspectorProxyMac.mm 2016-01-27 22:37:48 UTC (rev 195694)
@@ -568,7 +568,7 @@
if (base64Encoded) {
Vector<char> out;
- if (!base64Decode(contentCopy, out, Base64FailOnInvalidCharacterOrExcessPadding))
+ if (!base64Decode(contentCopy, out, Base64ValidatePadding))
return;
RetainPtr<NSData> dataContent = adoptNS([[NSData alloc] initWithBytes:out.data() length:out.size()]);
[dataContent writeToURL:actualURL atomically:YES];