WebKit Bugzilla
Attachment 342462 Details for
Bug 186538
: Add ByteString as a string that adheres to WebIDL ByteString constraints
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-186538-20180611135733.patch (text/plain), 35.76 KB, created by
youenn fablet
on 2018-06-11 13:57:37 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
youenn fablet
Created:
2018-06-11 13:57:37 PDT
Size:
35.76 KB
patch
obsolete
>Subversion Revision: 232536 >diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog >index 05db42447c58fa0bf37e7a8e514eaff731767a85..6c7b27064cdfde31e7278c889d12b1dd4f3bfe8f 100644 >--- a/Source/WTF/ChangeLog >+++ b/Source/WTF/ChangeLog >@@ -1,3 +1,22 @@ >+2018-06-11 Youenn Fablet <youenn@apple.com> >+ >+ Add ByteString as a string that adheres to WebIDL ByteString constraints >+ https://bugs.webkit.org/show_bug.cgi?id=186538 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add ByteString as a read-only string that only contains Latin1 characters as per WebIDL definition of ByteString. >+ >+ * WTF.xcodeproj/project.pbxproj: >+ * wtf/text/ByteString.h: Added. >+ (WTF::ByteString::ByteString): >+ (WTF::ByteString::fromLatin1String): >+ (WTF::ByteString::fromString): >+ (WTF::ByteString::operator const String& const): >+ (WTF::ByteString::value const): >+ (WTF::ByteString::isNull const): >+ (WTF::ByteString::isEmpty const): >+ > 2018-06-05 Darin Adler <darin@apple.com> > > [Cocoa] Retire DispatchPtr, and add more move semantics and simpler #ifs to other smart pointers >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index be78ae33bdd004a411a07a3ca7ad298c25e0e632..341bda348f301483ba0ad3950ad7573d9a68a375 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,58 @@ >+2018-06-11 Youenn Fablet <youenn@apple.com> >+ >+ Add ByteString as a string that adheres to WebIDL ByteString constraints >+ https://bugs.webkit.org/show_bug.cgi?id=186538 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Modify IDL conversion to instantiate WTF::ByteString instead of WTF::String. >+ Update implementation of Web APIs using WebIDL ByteString accordingly (XHR, Fetch). >+ >+ Update HTTPParsers validation routines to take ByteString so that they no longer need to check for non latin1 characters. >+ >+ In the future HTTPHeaderMap should probably get ByteString values. >+ >+ No change of behavior. >+ >+ * Modules/fetch/FetchHeaders.cpp: >+ (WebCore::canWriteHeader): >+ (WebCore::appendToHeaderMap): >+ (WebCore::fillHeaderMap): >+ (WebCore::FetchHeaders::append): >+ (WebCore::FetchHeaders::remove): >+ (WebCore::FetchHeaders::get const): >+ (WebCore::FetchHeaders::has const): >+ (WebCore::FetchHeaders::set): >+ (WebCore::FetchHeaders::filterAndFill): >+ * Modules/fetch/FetchHeaders.h: >+ * Modules/fetch/FetchRequest.cpp: >+ (WebCore::setMethod): >+ * Modules/fetch/FetchRequestInit.h: >+ * Modules/fetch/FetchResponse.h: >+ * bindings/IDLTypes.h: >+ * bindings/js/JSDOMConvertRecord.h: >+ (WebCore::Detail::IdentifierConverter<IDLByteString>::convert): >+ * bindings/js/JSDOMConvertStrings.h: >+ (WebCore::Converter<IDLByteString>::convert): >+ * platform/network/HTTPParsers.cpp: >+ (WebCore::isValidReasonPhrase): >+ (WebCore::isValidHTTPHeaderValue): >+ (WebCore::isValidAcceptHeaderValue): >+ (WebCore::isValidLanguageHeaderValue): >+ (WebCore::isValidHTTPToken): >+ (WebCore::isSimpleHeader): >+ (WebCore::isCrossOriginSafeRequestHeader): >+ * platform/network/HTTPParsers.h: >+ * testing/TypeConversions.h: >+ (WebCore::TypeConversions::testSequenceRecord const): >+ (WebCore::TypeConversions::setTestSequenceRecord): >+ * xml/XMLHttpRequest.cpp: >+ (WebCore::XMLHttpRequest::open): >+ (WebCore::XMLHttpRequest::setRequestHeader): >+ (WebCore::XMLHttpRequest::getAllResponseHeaders const): >+ (WebCore::XMLHttpRequest::getResponseHeader const): >+ * xml/XMLHttpRequest.h: >+ > 2018-06-08 Youenn Fablet <youenn@apple.com> > > Accept request header values should be more tightly checked after r232572 in case of CORS load >diff --git a/Source/WTF/WTF.xcodeproj/project.pbxproj b/Source/WTF/WTF.xcodeproj/project.pbxproj >index 862c7ccbc2f08e0c6ee8ee20728156eddef7d3ff..e7221d7774cf054d7b48d2e939915b64fd05906a 100644 >--- a/Source/WTF/WTF.xcodeproj/project.pbxproj >+++ b/Source/WTF/WTF.xcodeproj/project.pbxproj >@@ -328,6 +328,7 @@ > 313EDEC9778E49C9BEA91CFC /* StackTrace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StackTrace.cpp; sourceTree = "<group>"; }; > 37C7CC291EA40A73007BD956 /* WeakLinking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakLinking.h; sourceTree = "<group>"; }; > 391BD6BA4D164FD294F9A93D /* StdMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StdMap.h; sourceTree = "<group>"; }; >+ 4138F6E920CCF2590026DAA7 /* ByteString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ByteString.h; sourceTree = "<group>"; }; > 413FE8F51F8D2EAB00F6D7D7 /* CallbackAggregator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CallbackAggregator.h; sourceTree = "<group>"; }; > 430B47871AAAAC1A001223DA /* StringCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringCommon.h; sourceTree = "<group>"; }; > 46BA9EAB1F4CD61E009A2BBC /* CompletionHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompletionHandler.h; sourceTree = "<group>"; }; >@@ -1184,6 +1185,7 @@ > 9BD8F40A176C2AD80002D865 /* AtomicStringTable.h */, > 8134013615B092FD001FF0B8 /* Base64.cpp */, > 8134013715B092FD001FF0B8 /* Base64.h */, >+ 4138F6E920CCF2590026DAA7 /* ByteString.h */, > 0F8F2B9B172F2594007DBDA5 /* ConversionMode.h */, > A8A47321151A825B004123FF /* CString.cpp */, > A8A47322151A825B004123FF /* CString.h */, >diff --git a/Source/WTF/wtf/text/ByteString.h b/Source/WTF/wtf/text/ByteString.h >new file mode 100644 >index 0000000000000000000000000000000000000000..ff186909a05049a6cc293957e4ad16424d920d6f >--- /dev/null >+++ b/Source/WTF/wtf/text/ByteString.h >@@ -0,0 +1,70 @@ >+/* >+ * Copyright (C) 2018 Apple Inc. All rights reserved. >+ * >+ * This library is free software; you can redistribute it and/or >+ * modify it under the terms of the GNU Library General Public >+ * License as published by the Free Software Foundation; either >+ * version 2 of the License, or (at your option) any later version. >+ * >+ * This library is distributed in the hope that it will be useful, >+ * but WITHOUT ANY WARRANTY; without even the implied warranty of >+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU >+ * Library General Public License for more details. >+ * >+ * You should have received a copy of the GNU Library General Public License >+ * along with this library; see the file COPYING.LIB. If not, write to >+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, >+ * Boston, MA 02110-1301, USA. >+ * >+ */ >+ >+#pragma once >+ >+#include "WTFString.h" >+ >+namespace WTF { >+ >+class ByteString { >+public: >+ ByteString(ASCIILiteral&& value) >+ : m_value(WTFMove(value)) >+ { >+ } >+ >+ ByteString() = default; >+ >+ static ByteString fromLatin1String(String&& value) >+ { >+ ASSERT(value.isAllLatin1()); >+ return ByteString { WTFMove(value) }; >+ } >+ >+ static ByteString fromLatin1String(const String& value) >+ { >+ return fromLatin1String(String { value }); >+ } >+ >+ static std::optional<ByteString> fromString(String&& value) >+ { >+ if (!value.isAllLatin1()) >+ return std::nullopt; >+ return ByteString { WTFMove(value) }; >+ } >+ >+ operator const String&() const { return m_value; } >+ const String& value() const { return m_value; } >+ bool isNull() const { return m_value.isNull(); } >+ bool isEmpty() const { return m_value.isEmpty(); } >+ >+private: >+ explicit ByteString(String&& value) >+ : m_value(WTFMove(value)) >+ { >+ } >+ >+ String m_value; >+}; >+ >+} // namespace WTF >+ >+using WTF::ByteString; >diff --git a/Source/WebCore/Modules/fetch/FetchHeaders.cpp b/Source/WebCore/Modules/fetch/FetchHeaders.cpp >index d772fd0a3b591cb1d897d3e4fa2099d947b35906..b338e14f4c85000b797e124fccaf7a0999f5c9f5 100644 >--- a/Source/WebCore/Modules/fetch/FetchHeaders.cpp >+++ b/Source/WebCore/Modules/fetch/FetchHeaders.cpp >@@ -33,12 +33,13 @@ > > namespace WebCore { > >-static ExceptionOr<bool> canWriteHeader(const String& name, const String& value, FetchHeaders::Guard guard) >+static ExceptionOr<bool> canWriteHeader(const ByteString& name, const ByteString& value, FetchHeaders::Guard guard) > { >+ // FIXME: Add a special makeString adapter for ByteString. > if (!isValidHTTPToken(name)) >- return Exception { TypeError, makeString("Invalid header name: '", name, "'") }; >+ return Exception { TypeError, makeString("Invalid header name: '", name.value(), "'") }; > if (!isValidHTTPHeaderValue(value)) >- return Exception { TypeError, makeString("Header '", name, "' has invalid value: '", value, "'") }; >+ return Exception { TypeError, makeString("Header '", name.value(), "' has invalid value: '", value.value(), "'") }; > if (guard == FetchHeaders::Guard::Immutable) > return Exception { TypeError, ASCIILiteral("Headers object's guard is 'immutable'") }; > if (guard == FetchHeaders::Guard::Request && isForbiddenHeaderName(name)) >@@ -50,9 +51,9 @@ static ExceptionOr<bool> canWriteHeader(const String& name, const String& value, > return true; > } > >-static ExceptionOr<void> appendToHeaderMap(const String& name, const String& value, HTTPHeaderMap& headers, FetchHeaders::Guard guard) >+static ExceptionOr<void> appendToHeaderMap(const ByteString& name, const ByteString& value, HTTPHeaderMap& headers, FetchHeaders::Guard guard) > { >- String normalizedValue = stripLeadingAndTrailingHTTPSpaces(value); >+ auto normalizedValue = ByteString::fromLatin1String(stripLeadingAndTrailingHTTPSpaces(value)); > auto canWriteResult = canWriteHeader(name, normalizedValue, guard); > if (canWriteResult.hasException()) > return canWriteResult.releaseException(); >@@ -64,7 +65,7 @@ static ExceptionOr<void> appendToHeaderMap(const String& name, const String& val > > static ExceptionOr<void> appendToHeaderMap(const HTTPHeaderMap::HTTPHeaderMapConstIterator::KeyValue& header, HTTPHeaderMap& headers, FetchHeaders::Guard guard) > { >- auto canWriteResult = canWriteHeader(header.key, header.value, guard); >+ auto canWriteResult = canWriteHeader(ByteString::fromLatin1String(header.key), ByteString::fromLatin1String(header.value), guard); > if (canWriteResult.hasException()) > return canWriteResult.releaseException(); > if (!canWriteResult.releaseReturnValue()) >@@ -79,8 +80,8 @@ static ExceptionOr<void> appendToHeaderMap(const HTTPHeaderMap::HTTPHeaderMapCon > // https://fetch.spec.whatwg.org/#concept-headers-fill > static ExceptionOr<void> fillHeaderMap(HTTPHeaderMap& headers, const FetchHeaders::Init& headersInit, FetchHeaders::Guard guard) > { >- if (WTF::holds_alternative<Vector<Vector<String>>>(headersInit)) { >- auto& sequence = WTF::get<Vector<Vector<String>>>(headersInit); >+ if (WTF::holds_alternative<Vector<Vector<ByteString>>>(headersInit)) { >+ auto& sequence = WTF::get<Vector<Vector<ByteString>>>(headersInit); > for (auto& header : sequence) { > if (header.size() != 2) > return Exception { TypeError, "Header sub-sequence must contain exactly two items" }; >@@ -89,7 +90,7 @@ static ExceptionOr<void> fillHeaderMap(HTTPHeaderMap& headers, const FetchHeader > return result.releaseException(); > } > } else { >- auto& record = WTF::get<Vector<WTF::KeyValuePair<String, String>>>(headersInit); >+ auto& record = WTF::get<Vector<WTF::KeyValuePair<ByteString, ByteString>>>(headersInit); > for (auto& header : record) { > auto result = appendToHeaderMap(header.key, header.value, headers, guard); > if (result.hasException()) >@@ -129,12 +130,12 @@ ExceptionOr<void> FetchHeaders::fill(const FetchHeaders& otherHeaders) > return { }; > } > >-ExceptionOr<void> FetchHeaders::append(const String& name, const String& value) >+ExceptionOr<void> FetchHeaders::append(const ByteString& name, const ByteString& value) > { > return appendToHeaderMap(name, value, m_headers, m_guard); > } > >-ExceptionOr<void> FetchHeaders::remove(const String& name) >+ExceptionOr<void> FetchHeaders::remove(const ByteString& name) > { > auto canWriteResult = canWriteHeader(name, { }, m_guard); > if (canWriteResult.hasException()) >@@ -145,23 +146,23 @@ ExceptionOr<void> FetchHeaders::remove(const String& name) > return { }; > } > >-ExceptionOr<String> FetchHeaders::get(const String& name) const >+ExceptionOr<ByteString> FetchHeaders::get(const ByteString& name) const > { > if (!isValidHTTPToken(name)) >- return Exception { TypeError, makeString("Invalid header name: '", name, "'") }; >- return m_headers.get(name); >+ return Exception { TypeError, makeString("Invalid header name: '", name.value(), "'") }; >+ return ByteString::fromLatin1String(m_headers.get(name)); > } > >-ExceptionOr<bool> FetchHeaders::has(const String& name) const >+ExceptionOr<bool> FetchHeaders::has(const ByteString& name) const > { > if (!isValidHTTPToken(name)) >- return Exception { TypeError, makeString("Invalid header name: '", name, "'") }; >+ return Exception { TypeError, makeString("Invalid header name: '", name.value(), "'") }; > return m_headers.contains(name); > } > >-ExceptionOr<void> FetchHeaders::set(const String& name, const String& value) >+ExceptionOr<void> FetchHeaders::set(const ByteString& name, const ByteString& value) > { >- String normalizedValue = stripLeadingAndTrailingHTTPSpaces(value); >+ auto normalizedValue = ByteString::fromLatin1String(stripLeadingAndTrailingHTTPSpaces(value)); > auto canWriteResult = canWriteHeader(name, normalizedValue, m_guard); > if (canWriteResult.hasException()) > return canWriteResult.releaseException(); >@@ -174,7 +175,7 @@ ExceptionOr<void> FetchHeaders::set(const String& name, const String& value) > void FetchHeaders::filterAndFill(const HTTPHeaderMap& headers, Guard guard) > { > for (auto& header : headers) { >- auto canWriteResult = canWriteHeader(header.key, header.value, guard); >+ auto canWriteResult = canWriteHeader(ByteString::fromLatin1String(header.key), ByteString::fromLatin1String(header.value), guard); > if (canWriteResult.hasException()) > continue; > if (!canWriteResult.releaseReturnValue()) >diff --git a/Source/WebCore/Modules/fetch/FetchHeaders.h b/Source/WebCore/Modules/fetch/FetchHeaders.h >index cfb1d7e2b3b271cbe5ba4dfba5a88caf1099547c..dc9fc0022dce3c42bcbbd268cdb6070c7e4a4f06 100644 >--- a/Source/WebCore/Modules/fetch/FetchHeaders.h >+++ b/Source/WebCore/Modules/fetch/FetchHeaders.h >@@ -34,6 +34,7 @@ > #include <wtf/HashTraits.h> > #include <wtf/Variant.h> > #include <wtf/Vector.h> >+#include <wtf/text/ByteString.h> > > namespace WebCore { > >@@ -47,17 +48,17 @@ public: > Response > }; > >- using Init = Variant<Vector<Vector<String>>, Vector<WTF::KeyValuePair<String, String>>>; >+ using Init = Variant<Vector<Vector<ByteString>>, Vector<WTF::KeyValuePair<ByteString, ByteString>>>; > static ExceptionOr<Ref<FetchHeaders>> create(std::optional<Init>&&); > > static Ref<FetchHeaders> create(Guard guard = Guard::None, HTTPHeaderMap&& headers = { }) { return adoptRef(*new FetchHeaders { guard, WTFMove(headers) }); } > static Ref<FetchHeaders> create(const FetchHeaders& headers) { return adoptRef(*new FetchHeaders { headers }); } > >- ExceptionOr<void> append(const String& name, const String& value); >- ExceptionOr<void> remove(const String&); >- ExceptionOr<String> get(const String&) const; >- ExceptionOr<bool> has(const String&) const; >- ExceptionOr<void> set(const String& name, const String& value); >+ ExceptionOr<void> append(const ByteString& name, const ByteString& value); >+ ExceptionOr<void> remove(const ByteString&); >+ ExceptionOr<ByteString> get(const ByteString&) const; >+ ExceptionOr<bool> has(const ByteString&) const; >+ ExceptionOr<void> set(const ByteString& name, const ByteString& value); > > ExceptionOr<void> fill(const Init&); > ExceptionOr<void> fill(const FetchHeaders&); >diff --git a/Source/WebCore/Modules/fetch/FetchRequest.cpp b/Source/WebCore/Modules/fetch/FetchRequest.cpp >index 8af9965acb5ccd08b8a45d473db415a3ca26a729..2097d6f62bea46b554edfd93fb780902ab6d7e9e 100644 >--- a/Source/WebCore/Modules/fetch/FetchRequest.cpp >+++ b/Source/WebCore/Modules/fetch/FetchRequest.cpp >@@ -35,7 +35,7 @@ > > namespace WebCore { > >-static std::optional<Exception> setMethod(ResourceRequest& request, const String& initMethod) >+static std::optional<Exception> setMethod(ResourceRequest& request, const ByteString& initMethod) > { > if (!isValidHTTPToken(initMethod)) > return Exception { TypeError, ASCIILiteral("Method is not a valid HTTP token.") }; >diff --git a/Source/WebCore/Modules/fetch/FetchRequestInit.h b/Source/WebCore/Modules/fetch/FetchRequestInit.h >index 97b001681e7f1ba4d30cfd84aed4ad9d7ea97b70..11376aa42aa9b1146ca0f5a142455379797bf00d 100644 >--- a/Source/WebCore/Modules/fetch/FetchRequestInit.h >+++ b/Source/WebCore/Modules/fetch/FetchRequestInit.h >@@ -30,12 +30,12 @@ > #include "FetchOptions.h" > #include <JavaScriptCore/JSCJSValue.h> > #include <wtf/Optional.h> >-#include <wtf/text/WTFString.h> >+#include <wtf/text/ByteString.h> > > namespace WebCore { > > struct FetchRequestInit { >- String method; >+ ByteString method; > std::optional<FetchHeaders::Init> headers; > std::optional<FetchBody::Init> body; > String referrer; >diff --git a/Source/WebCore/Modules/fetch/FetchResponse.h b/Source/WebCore/Modules/fetch/FetchResponse.h >index 47e2ebab6aeb8a96b6eaa9bff70d31bc70b136cb..9ae1a3311ff74b01f056a13d096eedd40b3026d2 100644 >--- a/Source/WebCore/Modules/fetch/FetchResponse.h >+++ b/Source/WebCore/Modules/fetch/FetchResponse.h >@@ -51,7 +51,7 @@ public: > > struct Init { > unsigned short status { 200 }; >- String statusText { ASCIILiteral("OK") }; >+ ByteString statusText { ASCIILiteral("OK") }; > std::optional<FetchHeaders::Init> headers; > }; > >diff --git a/Source/WebCore/bindings/IDLTypes.h b/Source/WebCore/bindings/IDLTypes.h >index 8057dfa115888d3db4a0f0be26b4c662b69c787c..a75be2c763f78c319fcedc2551170b7c4801f56d 100644 >--- a/Source/WebCore/bindings/IDLTypes.h >+++ b/Source/WebCore/bindings/IDLTypes.h >@@ -31,7 +31,7 @@ > #include <wtf/Brigand.h> > #include <wtf/HashMap.h> > #include <wtf/StdLibExtras.h> >-#include <wtf/text/WTFString.h> >+#include <wtf/text/ByteString.h> > > #if ENABLE(WEBGL) > #include "WebGLAny.h" >@@ -134,7 +134,7 @@ template<typename StringType> struct IDLString : IDLType<StringType> { > template <typename U> static U&& extractValueFromNullable(U&& value) { return std::forward<U>(value); } > }; > struct IDLDOMString : IDLString<String> { }; >-struct IDLByteString : IDLString<String> { }; >+struct IDLByteString : IDLString<ByteString> { }; > struct IDLUSVString : IDLString<String> { }; > > template<typename T> struct IDLTreatNullAsEmptyAdaptor : IDLString<String> { >diff --git a/Source/WebCore/bindings/js/JSDOMConvertRecord.h b/Source/WebCore/bindings/js/JSDOMConvertRecord.h >index 75b2eb6aecd2c08db2ac3c4ca63077d119f8f587..7e18c0f2f7823a011b4a02365745d6b45d8b67ae 100644 >--- a/Source/WebCore/bindings/js/JSDOMConvertRecord.h >+++ b/Source/WebCore/bindings/js/JSDOMConvertRecord.h >@@ -44,7 +44,7 @@ template<> struct IdentifierConverter<IDLDOMString> { > }; > > template<> struct IdentifierConverter<IDLByteString> { >- static String convert(JSC::ExecState& state, const JSC::Identifier& identifier) >+ static ByteString convert(JSC::ExecState& state, const JSC::Identifier& identifier) > { > return identifierToByteString(state, identifier); > } >diff --git a/Source/WebCore/bindings/js/JSDOMConvertStrings.cpp b/Source/WebCore/bindings/js/JSDOMConvertStrings.cpp >index 1ca1ce3dd1aee6e7de3b66b1f6513f6a38e4f55d..74e85d21f9ba495ce96d745a1fa6006d0a0d7226 100644 >--- a/Source/WebCore/bindings/js/JSDOMConvertStrings.cpp >+++ b/Source/WebCore/bindings/js/JSDOMConvertStrings.cpp >@@ -32,17 +32,18 @@ > namespace WebCore { > using namespace JSC; > >-static inline String stringToByteString(ExecState& state, JSC::ThrowScope& scope, String&& string) >+static inline ByteString stringToByteString(ExecState& state, JSC::ThrowScope& scope, String&& string) > { >- if (!string.isAllLatin1()) { >+ auto byteString = ByteString::fromString(WTFMove(string)); >+ if (!byteString) { > throwTypeError(&state, scope); > return { }; > } > >- return WTFMove(string); >+ return WTFMove(*byteString); > } > >-String identifierToByteString(ExecState& state, const Identifier& identifier) >+ByteString identifierToByteString(ExecState& state, const Identifier& identifier) > { > VM& vm = state.vm(); > auto scope = DECLARE_THROW_SCOPE(vm); >@@ -51,7 +52,7 @@ String identifierToByteString(ExecState& state, const Identifier& identifier) > return stringToByteString(state, scope, WTFMove(string)); > } > >-String valueToByteString(ExecState& state, JSValue value) >+ByteString valueToByteString(ExecState& state, JSValue value) > { > VM& vm = state.vm(); > auto scope = DECLARE_THROW_SCOPE(vm); >diff --git a/Source/WebCore/bindings/js/JSDOMConvertStrings.h b/Source/WebCore/bindings/js/JSDOMConvertStrings.h >index dc89cbf14595a72e8f9df2ea240ed85dbe7b471f..dfa2edae71654d7a3751eadec3c8d0c9fdc0fcf1 100644 >--- a/Source/WebCore/bindings/js/JSDOMConvertStrings.h >+++ b/Source/WebCore/bindings/js/JSDOMConvertStrings.h >@@ -25,14 +25,15 @@ > > #pragma once > >+#include <wtf/text/ByteString.h> > #include "IDLTypes.h" > #include "JSDOMConvertBase.h" > #include "StringAdaptors.h" > > namespace WebCore { > >-WEBCORE_EXPORT String identifierToByteString(JSC::ExecState&, const JSC::Identifier&); >-WEBCORE_EXPORT String valueToByteString(JSC::ExecState&, JSC::JSValue); >+WEBCORE_EXPORT ByteString identifierToByteString(JSC::ExecState&, const JSC::Identifier&); >+WEBCORE_EXPORT ByteString valueToByteString(JSC::ExecState&, JSC::JSValue); > WEBCORE_EXPORT String identifierToUSVString(JSC::ExecState&, const JSC::Identifier&); > WEBCORE_EXPORT String valueToUSVString(JSC::ExecState&, JSC::JSValue); > >@@ -78,9 +79,12 @@ template<> struct JSConverter<IDLDOMString> { > }; > > template<> struct Converter<IDLByteString> : DefaultConverter<IDLByteString> { >- static String convert(JSC::ExecState& state, JSC::JSValue value) >+ using ReturnType = ByteString; >+ static constexpr bool conversionHasSideEffects = true; >+ >+ static ByteString convert(JSC::ExecState& state, JSC::JSValue value) > { >- return valueToByteString(state, value); >+ return ByteString::fromLatin1String(valueToByteString(state, value)); > } > }; > >diff --git a/Source/WebCore/platform/network/HTTPParsers.cpp b/Source/WebCore/platform/network/HTTPParsers.cpp >index e8337d1629eba797801b0b3523baf30891b78301..6a9646c35443200b198d16acd1332504ea09fbcc 100644 >--- a/Source/WebCore/platform/network/HTTPParsers.cpp >+++ b/Source/WebCore/platform/network/HTTPParsers.cpp >@@ -100,19 +100,22 @@ static inline bool skipValue(const String& str, unsigned& pos) > } > > // See RFC 7230, Section 3.1.2. >-bool isValidReasonPhrase(const String& value) >+bool isValidReasonPhrase(const ByteString& byteValue) > { >+ auto& value = byteValue.value(); > for (unsigned i = 0; i < value.length(); ++i) { > UChar c = value[i]; >- if (c == 0x7F || c > 0xFF || (c < 0x20 && c != '\t')) >+ ASSERT(c <= 0xFF); >+ if (c == 0x7F || (c < 0x20 && c != '\t')) > return false; > } > return true; > } > > // See https://fetch.spec.whatwg.org/#concept-header >-bool isValidHTTPHeaderValue(const String& value) >+bool isValidHTTPHeaderValue(const ByteString& byteValue) > { >+ auto& value = byteValue.value(); > UChar c = value[0]; > if (c == ' ' || c == '\t') > return false; >@@ -138,8 +141,9 @@ static bool isDelimiterCharacter(const UChar c) > } > > // See RFC 7231, Section 5.3.2. >-bool isValidAcceptHeaderValue(const String& value) >+bool isValidAcceptHeaderValue(const ByteString& byteValue) > { >+ auto& value = byteValue.value(); > for (unsigned i = 0; i < value.length(); ++i) { > UChar c = value[i]; > >@@ -159,12 +163,14 @@ bool isValidAcceptHeaderValue(const String& value) > } > > // See RFC 7231, Section 5.3.5 and 3.1.3.2. >-bool isValidLanguageHeaderValue(const String& value) >+bool isValidLanguageHeaderValue(const ByteString& byteValue) > { >+ auto& value = byteValue.value(); > for (unsigned i = 0; i < value.length(); ++i) { > UChar c = value[i]; > if (isASCIIAlphanumeric(c) || c == ' ' || c == '*' || c == ',' || c == '-' || c == '.' || c == ';' || c == '=') > continue; >+ ASSERT(c <= 0xFF); > return false; > } > >@@ -176,12 +182,14 @@ bool isValidLanguageHeaderValue(const String& value) > } > > // See RFC 7230, Section 3.2.6. >-bool isValidHTTPToken(const String& value) >+bool isValidHTTPToken(const ByteString& byteValue) > { >+ auto& value = byteValue.value(); > if (value.isEmpty()) > return false; > auto valueStringView = StringView(value); > for (UChar c : valueStringView.codeUnits()) { >+ ASSERT(c <= 0xFF); > if (c <= 0x20 || c >= 0x7F > || c == '(' || c == ')' || c == '<' || c == '>' || c == '@' > || c == ',' || c == ';' || c == ':' || c == '\\' || c == '"' >@@ -832,7 +840,7 @@ bool isForbiddenMethod(const String& name) > return equalLettersIgnoringASCIICase(name, "connect") || equalLettersIgnoringASCIICase(name, "trace") || equalLettersIgnoringASCIICase(name, "track"); > } > >-bool isSimpleHeader(const String& name, const String& value) >+bool isSimpleHeader(const String& name, const ByteString& value) > { > HTTPHeaderName headerName; > if (!findHTTPHeaderName(name, headerName)) >@@ -870,7 +878,7 @@ bool isCrossOriginSafeHeader(const String& name, const HTTPHeaderSet& accessCont > } > > // Implements https://fetch.spec.whatwg.org/#cors-safelisted-request-header >-bool isCrossOriginSafeRequestHeader(HTTPHeaderName name, const String& value) >+bool isCrossOriginSafeRequestHeader(HTTPHeaderName name, const ByteString& value) > { > switch (name) { > case HTTPHeaderName::Accept: >@@ -889,6 +897,13 @@ bool isCrossOriginSafeRequestHeader(HTTPHeaderName name, const String& value) > } > } > >+bool isCrossOriginSafeRequestHeader(HTTPHeaderName name, const String& value) >+{ >+ if (auto byteValue = ByteString::fromString(value)) >+ return isCrossOriginSafeRequestHeader(name, *byteValue); >+ return false; >+} >+ > // Implements <https://fetch.spec.whatwg.org/#concept-method-normalize>. > String normalizeHTTPMethod(const String& method) > { >diff --git a/Source/WebCore/platform/network/HTTPParsers.h b/Source/WebCore/platform/network/HTTPParsers.h >index 5d55551b174b39d0b9d1a49c847410e329ccf8e6..e334bdd57be210b0208f3b4f287dcc835b463c44 100644 >--- a/Source/WebCore/platform/network/HTTPParsers.h >+++ b/Source/WebCore/platform/network/HTTPParsers.h >@@ -34,8 +34,8 @@ > #include <wtf/HashSet.h> > #include <wtf/Optional.h> > #include <wtf/WallTime.h> >+#include <wtf/text/ByteString.h> > #include <wtf/text/StringHash.h> >-#include <wtf/text/WTFString.h> > > namespace WebCore { > >@@ -78,11 +78,11 @@ enum class CrossOriginWindowPolicy { > Allow, > }; > >-bool isValidReasonPhrase(const String&); >-bool isValidHTTPHeaderValue(const String&); >-bool isValidAcceptHeaderValue(const String&); >-bool isValidLanguageHeaderValue(const String&); >-bool isValidHTTPToken(const String&); >+bool isValidReasonPhrase(const ByteString&); >+bool isValidHTTPHeaderValue(const ByteString&); >+bool isValidAcceptHeaderValue(const ByteString&); >+bool isValidLanguageHeaderValue(const ByteString&); >+bool isValidHTTPToken(const ByteString&); > bool parseHTTPRefresh(const String& refresh, double& delay, String& url); > std::optional<WallTime> parseHTTPDate(const String&); > String filenameFromHTTPContentDisposition(const String&); >@@ -110,9 +110,10 @@ void parseAccessControlExposeHeadersAllowList(const String& headerValue, HTTPHea > bool isForbiddenHeaderName(const String&); > bool isForbiddenResponseHeaderName(const String&); > bool isForbiddenMethod(const String&); >-bool isSimpleHeader(const String& name, const String& value); >+bool isSimpleHeader(const String& name, const ByteString& value); > bool isCrossOriginSafeHeader(HTTPHeaderName, const HTTPHeaderSet&); > bool isCrossOriginSafeHeader(const String&, const HTTPHeaderSet&); >+bool isCrossOriginSafeRequestHeader(HTTPHeaderName, const ByteString&); > bool isCrossOriginSafeRequestHeader(HTTPHeaderName, const String&); > > String normalizeHTTPMethod(const String&); >diff --git a/Source/WebCore/testing/TypeConversions.h b/Source/WebCore/testing/TypeConversions.h >index e35c117d9684198ea013bcdcbac7e2d6a229b935..29028750d4ff83ac980678de05368cd462fb70f3 100644 >--- a/Source/WebCore/testing/TypeConversions.h >+++ b/Source/WebCore/testing/TypeConversions.h >@@ -119,8 +119,8 @@ public: > void setTestLongRecord(const Vector<WTF::KeyValuePair<String, int>>& value) { m_longRecord = value; } > const Vector<WTF::KeyValuePair<String, RefPtr<Node>>>& testNodeRecord() const { return m_nodeRecord; } > void setTestNodeRecord(const Vector<WTF::KeyValuePair<String, RefPtr<Node>>>& value) { m_nodeRecord = value; } >- const Vector<WTF::KeyValuePair<String, Vector<String>>>& testSequenceRecord() const { return m_sequenceRecord; } >- void setTestSequenceRecord(const Vector<WTF::KeyValuePair<String, Vector<String>>>& value) { m_sequenceRecord = value; } >+ const Vector<WTF::KeyValuePair<ByteString, Vector<String>>>& testSequenceRecord() const { return m_sequenceRecord; } >+ void setTestSequenceRecord(const Vector<WTF::KeyValuePair<ByteString, Vector<String>>>& value) { m_sequenceRecord = value; } > > using TestUnion = Variant<String, int, bool, RefPtr<Node>, Vector<int>>; > const TestUnion& testUnion() const { return m_union; } >@@ -164,7 +164,7 @@ private: > String m_treatNullAsEmptyString; > Vector<WTF::KeyValuePair<String, int>> m_longRecord; > Vector<WTF::KeyValuePair<String, RefPtr<Node>>> m_nodeRecord; >- Vector<WTF::KeyValuePair<String, Vector<String>>> m_sequenceRecord; >+ Vector<WTF::KeyValuePair<ByteString, Vector<String>>> m_sequenceRecord; > > Dictionary m_testDictionary; > >diff --git a/Source/WebCore/xml/XMLHttpRequest.cpp b/Source/WebCore/xml/XMLHttpRequest.cpp >index 53c0f23ce9254fc862d9df945e210e806f8da20c..62cf375c7a9576442a42d4491f4400bbd39f02ba 100644 >--- a/Source/WebCore/xml/XMLHttpRequest.cpp >+++ b/Source/WebCore/xml/XMLHttpRequest.cpp >@@ -320,13 +320,13 @@ ExceptionOr<void> XMLHttpRequest::setWithCredentials(bool value) > return { }; > } > >-ExceptionOr<void> XMLHttpRequest::open(const String& method, const String& url) >+ExceptionOr<void> XMLHttpRequest::open(const ByteString& method, const String& url) > { > // If the async argument is omitted, set async to true. > return open(method, scriptExecutionContext()->completeURL(url), true); > } > >-ExceptionOr<void> XMLHttpRequest::open(const String& method, const URL& url, bool async) >+ExceptionOr<void> XMLHttpRequest::open(const ByteString& method, const URL& url, bool async) > { > if (!isValidHTTPToken(method)) > return Exception { SyntaxError }; >@@ -377,7 +377,7 @@ ExceptionOr<void> XMLHttpRequest::open(const String& method, const URL& url, boo > return { }; > } > >-ExceptionOr<void> XMLHttpRequest::open(const String& method, const String& url, bool async, const String& user, const String& password) >+ExceptionOr<void> XMLHttpRequest::open(const ByteString& method, const String& url, bool async, const String& user, const String& password) > { > URL urlWithCredentials = scriptExecutionContext()->completeURL(url); > if (!user.isNull()) { >@@ -772,7 +772,7 @@ ExceptionOr<void> XMLHttpRequest::overrideMimeType(const String& override) > return { }; > } > >-ExceptionOr<void> XMLHttpRequest::setRequestHeader(const String& name, const String& value) >+ExceptionOr<void> XMLHttpRequest::setRequestHeader(const ByteString& name, const ByteString& value) > { > if (m_state != OPENED || m_sendFlag) { > #if ENABLE(DASHBOARD_SUPPORT) >@@ -782,7 +782,7 @@ ExceptionOr<void> XMLHttpRequest::setRequestHeader(const String& name, const Str > return Exception { InvalidStateError }; > } > >- String normalizedValue = stripLeadingAndTrailingHTTPSpaces(value); >+ auto normalizedValue = ByteString::fromLatin1String(stripLeadingAndTrailingHTTPSpaces(value)); > if (!isValidHTTPToken(name) || !isValidHTTPHeaderValue(normalizedValue)) > return Exception { SyntaxError }; > >@@ -793,7 +793,7 @@ ExceptionOr<void> XMLHttpRequest::setRequestHeader(const String& name, const Str > if (securityOrigin()->canLoadLocalResources() && document()->settings().allowSettingAnyXHRHeaderFromFileURLs()) > allowUnsafeHeaderField = true; > if (!allowUnsafeHeaderField && isForbiddenHeaderName(name)) { >- logConsoleError(scriptExecutionContext(), "Refused to set unsafe header \"" + name + "\""); >+ logConsoleError(scriptExecutionContext(), "Refused to set unsafe header \"" + name.value() + "\""); > return { }; > } > >@@ -801,10 +801,10 @@ ExceptionOr<void> XMLHttpRequest::setRequestHeader(const String& name, const Str > return { }; > } > >-String XMLHttpRequest::getAllResponseHeaders() const >+ByteString XMLHttpRequest::getAllResponseHeaders() const > { > if (m_state < HEADERS_RECEIVED || m_error) >- return emptyString(); >+ return ByteString::fromLatin1String(emptyString()); > > if (!m_allResponseHeaders) { > Vector<String> headers; >@@ -826,15 +826,15 @@ String XMLHttpRequest::getAllResponseHeaders() const > m_allResponseHeaders = stringBuilder.toString(); > } > >- return m_allResponseHeaders; >+ return ByteString::fromLatin1String(m_allResponseHeaders); > } > >-String XMLHttpRequest::getResponseHeader(const String& name) const >+ByteString XMLHttpRequest::getResponseHeader(const String& name) const > { > if (m_state < HEADERS_RECEIVED || m_error) >- return String(); >+ return ByteString { }; > >- return m_response.httpHeaderField(name); >+ return ByteString::fromLatin1String(m_response.httpHeaderField(name)); > } > > String XMLHttpRequest::responseMIMEType() const >diff --git a/Source/WebCore/xml/XMLHttpRequest.h b/Source/WebCore/xml/XMLHttpRequest.h >index e32d01335cab370600bf06b622e379e267d6fce2..a415b90e2d7aa940b98e7c476cd8a7e90ecc280a 100644 >--- a/Source/WebCore/xml/XMLHttpRequest.h >+++ b/Source/WebCore/xml/XMLHttpRequest.h >@@ -30,6 +30,7 @@ > #include "XMLHttpRequestEventTarget.h" > #include "XMLHttpRequestProgressEventThrottle.h" > #include <wtf/Variant.h> >+#include <wtf/text/ByteString.h> > #include <wtf/text/StringBuilder.h> > > namespace JSC { >@@ -76,16 +77,16 @@ public: > State readyState() const; > bool withCredentials() const { return m_includeCredentials; } > ExceptionOr<void> setWithCredentials(bool); >- ExceptionOr<void> open(const String& method, const String& url); >- ExceptionOr<void> open(const String& method, const URL&, bool async); >- ExceptionOr<void> open(const String& method, const String&, bool async, const String& user, const String& password); >+ ExceptionOr<void> open(const ByteString& method, const String& url); >+ ExceptionOr<void> open(const ByteString& method, const URL&, bool async); >+ ExceptionOr<void> open(const ByteString& method, const String&, bool async, const String& user, const String& password); > ExceptionOr<void> send(std::optional<SendTypes>&&); > void abort(); >- ExceptionOr<void> setRequestHeader(const String& name, const String& value); >+ ExceptionOr<void> setRequestHeader(const ByteString& name, const ByteString& value); > ExceptionOr<void> overrideMimeType(const String& override); > bool doneWithoutErrors() const { return !m_error && m_state == DONE; } >- String getAllResponseHeaders() const; >- String getResponseHeader(const String& name) const; >+ ByteString getAllResponseHeaders() const; >+ ByteString getResponseHeader(const String& name) const; > ExceptionOr<OwnedString> responseText(); > String responseTextIgnoringResponseType() const { return m_responseBuilder.toStringPreserveCapacity(); } > String responseMIMEType() const;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 186538
:
342462
|
342486
|
342502