Diff
Modified: branches/safari-609-branch/Source/WTF/ChangeLog (262551 => 262552)
--- branches/safari-609-branch/Source/WTF/ChangeLog 2020-06-04 19:00:32 UTC (rev 262551)
+++ branches/safari-609-branch/Source/WTF/ChangeLog 2020-06-04 19:00:36 UTC (rev 262552)
@@ -1,3 +1,57 @@
+2020-06-04 Alan Coon <[email protected]>
+
+ Cherry-pick r262171. rdar://problem/63950945
+
+ UTF-8 encode strings of invalid URLs when converting WTF::URL to NSURL instead of truncating the UTF-16 encoding
+ https://bugs.webkit.org/show_bug.cgi?id=212393
+ <rdar://problem/63095503>
+
+ Patch by Alex Christensen <[email protected]> on 2020-05-26
+ Reviewed by Tim Horton.
+
+ Source/WTF:
+
+ This only changes behavior in code that is marked as UNLIKELY because it can only be reached by invalid unicode URLs,
+ but it can be reached and should behave in a reasonable manner in those cases. This makes Safari behave more similarly
+ to Firefox in this case instead of doing something similar to no other browser.
+
+ * wtf/URL.cpp:
+ (WTF::copyASCII): Deleted.
+ (WTF::URL::copyToBuffer const): Deleted.
+ * wtf/URL.h:
+ * wtf/cf/URLCF.cpp:
+ (WTF::URL::createCFURL const):
+ * wtf/cocoa/URLCocoa.mm:
+ (WTF::URL::createCFURL const):
+
+ Tools:
+
+ * TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm:
+ (TestWebKitAPI::TEST):
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@262171 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2020-05-26 Alex Christensen <[email protected]>
+
+ UTF-8 encode strings of invalid URLs when converting WTF::URL to NSURL instead of truncating the UTF-16 encoding
+ https://bugs.webkit.org/show_bug.cgi?id=212393
+ <rdar://problem/63095503>
+
+ Reviewed by Tim Horton.
+
+ This only changes behavior in code that is marked as UNLIKELY because it can only be reached by invalid unicode URLs,
+ but it can be reached and should behave in a reasonable manner in those cases. This makes Safari behave more similarly
+ to Firefox in this case instead of doing something similar to no other browser.
+
+ * wtf/URL.cpp:
+ (WTF::copyASCII): Deleted.
+ (WTF::URL::copyToBuffer const): Deleted.
+ * wtf/URL.h:
+ * wtf/cf/URLCF.cpp:
+ (WTF::URL::createCFURL const):
+ * wtf/cocoa/URLCocoa.mm:
+ (WTF::URL::createCFURL const):
+
2020-05-20 Alan Coon <[email protected]>
Cherry-pick r261877. rdar://problem/63461428
Modified: branches/safari-609-branch/Source/WTF/wtf/URL.cpp (262551 => 262552)
--- branches/safari-609-branch/Source/WTF/wtf/URL.cpp 2020-06-04 19:00:32 UTC (rev 262551)
+++ branches/safari-609-branch/Source/WTF/wtf/URL.cpp 2020-06-04 19:00:36 UTC (rev 262552)
@@ -47,24 +47,6 @@
static constexpr unsigned invalidPortNumber = 0xFFFF;
-// Copies the source to the destination, assuming all the source characters are
-// ASCII. The destination buffer must be large enough. Null characters are allowed
-// in the source string, and no attempt is made to null-terminate the result.
-static void copyASCII(const String& string, char* dest)
-{
- if (string.isEmpty())
- return;
-
- if (string.is8Bit())
- memcpy(dest, string.characters8(), string.length());
- else {
- const UChar* src = ""
- size_t length = string.length();
- for (size_t i = 0; i < length; i++)
- dest[i] = static_cast<char>(src[i]);
- }
-}
-
void URL::invalidate()
{
m_isValid = false;
@@ -773,14 +755,6 @@
return m_string[m_schemeEnd + 1] == '/';
}
-void URL::copyToBuffer(Vector<char, 512>& buffer) const
-{
- // FIXME: This throws away the high bytes of all the characters in the string!
- // That's fine for a valid URL, which is all ASCII, but not for invalid URLs.
- buffer.resize(m_string.length());
- copyASCII(m_string, buffer.data());
-}
-
template<typename StringClass>
bool protocolIsInternal(const StringClass& url, const char* protocol)
{
Modified: branches/safari-609-branch/Source/WTF/wtf/URL.h (262551 => 262552)
--- branches/safari-609-branch/Source/WTF/wtf/URL.h 2020-06-04 19:00:32 UTC (rev 262551)
+++ branches/safari-609-branch/Source/WTF/wtf/URL.h 2020-06-04 19:00:36 UTC (rev 262552)
@@ -197,7 +197,6 @@
friend class URLParser;
void invalidate();
static bool protocolIs(const String&, const char*);
- void copyToBuffer(Vector<char, 512>& buffer) const;
unsigned hostStart() const;
friend WTF_EXPORT_PRIVATE bool equalIgnoringFragmentIdentifier(const URL&, const URL&);
Modified: branches/safari-609-branch/Source/WTF/wtf/cf/URLCF.cpp (262551 => 262552)
--- branches/safari-609-branch/Source/WTF/wtf/cf/URLCF.cpp 2020-06-04 19:00:32 UTC (rev 262551)
+++ branches/safari-609-branch/Source/WTF/wtf/cf/URLCF.cpp 2020-06-04 19:00:36 UTC (rev 262552)
@@ -50,12 +50,13 @@
#if !USE(FOUNDATION)
RetainPtr<CFURLRef> URL::createCFURL() const
{
- // FIXME: What should this return for invalid URLs?
- // Currently it throws away the high bytes of the characters in the string in that case,
- // which is clearly wrong.
- URLCharBuffer buffer;
- copyToBuffer(buffer);
- auto cfURL = createCFURLFromBuffer(buffer.data(), buffer.size());
+ RetainPtr<CFURLRef> cfURL;
+ if (LIKELY(m_string.is8Bit()))
+ cfURL = WTF::createCFURLFromBuffer(reinterpret_cast<const char*>(m_string.characters8()), m_string.length());
+ else {
+ CString utf8 = m_string.utf8();
+ cfURL = WTF::createCFURLFromBuffer(utf8.data(), utf8.length());
+ }
if (protocolIsInHTTPFamily() && !isCFURLSameOrigin(cfURL.get(), *this))
return nullptr;
Modified: branches/safari-609-branch/Source/WTF/wtf/cocoa/URLCocoa.mm (262551 => 262552)
--- branches/safari-609-branch/Source/WTF/wtf/cocoa/URLCocoa.mm 2020-06-04 19:00:32 UTC (rev 262551)
+++ branches/safari-609-branch/Source/WTF/wtf/cocoa/URLCocoa.mm 2020-06-04 19:00:36 UTC (rev 262552)
@@ -70,15 +70,11 @@
}
RetainPtr<CFURLRef> cfURL;
-
- // Fast path if the input data is 8-bit to avoid copying into a temporary buffer.
if (LIKELY(m_string.is8Bit()))
cfURL = WTF::createCFURLFromBuffer(reinterpret_cast<const char*>(m_string.characters8()), m_string.length());
else {
- // Slower path.
- WTF::URLCharBuffer buffer;
- copyToBuffer(buffer);
- cfURL = WTF::createCFURLFromBuffer(buffer.data(), buffer.size());
+ CString utf8 = m_string.utf8();
+ cfURL = WTF::createCFURLFromBuffer(utf8.data(), utf8.length());
}
if (protocolIsInHTTPFamily() && !WTF::isCFURLSameOrigin(cfURL.get(), *this))
Modified: branches/safari-609-branch/Tools/ChangeLog (262551 => 262552)
--- branches/safari-609-branch/Tools/ChangeLog 2020-06-04 19:00:32 UTC (rev 262551)
+++ branches/safari-609-branch/Tools/ChangeLog 2020-06-04 19:00:36 UTC (rev 262552)
@@ -1,3 +1,47 @@
+2020-06-04 Alan Coon <[email protected]>
+
+ Cherry-pick r262171. rdar://problem/63950945
+
+ UTF-8 encode strings of invalid URLs when converting WTF::URL to NSURL instead of truncating the UTF-16 encoding
+ https://bugs.webkit.org/show_bug.cgi?id=212393
+ <rdar://problem/63095503>
+
+ Patch by Alex Christensen <[email protected]> on 2020-05-26
+ Reviewed by Tim Horton.
+
+ Source/WTF:
+
+ This only changes behavior in code that is marked as UNLIKELY because it can only be reached by invalid unicode URLs,
+ but it can be reached and should behave in a reasonable manner in those cases. This makes Safari behave more similarly
+ to Firefox in this case instead of doing something similar to no other browser.
+
+ * wtf/URL.cpp:
+ (WTF::copyASCII): Deleted.
+ (WTF::URL::copyToBuffer const): Deleted.
+ * wtf/URL.h:
+ * wtf/cf/URLCF.cpp:
+ (WTF::URL::createCFURL const):
+ * wtf/cocoa/URLCocoa.mm:
+ (WTF::URL::createCFURL const):
+
+ Tools:
+
+ * TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm:
+ (TestWebKitAPI::TEST):
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@262171 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2020-05-26 Alex Christensen <[email protected]>
+
+ UTF-8 encode strings of invalid URLs when converting WTF::URL to NSURL instead of truncating the UTF-16 encoding
+ https://bugs.webkit.org/show_bug.cgi?id=212393
+ <rdar://problem/63095503>
+
+ Reviewed by Tim Horton.
+
+ * TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm:
+ (TestWebKitAPI::TEST):
+
2020-05-28 Ryan Haddad <[email protected]>
Cherry-pick r262143. rdar://problem/63517635
Modified: branches/safari-609-branch/Tools/TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm (262551 => 262552)
--- branches/safari-609-branch/Tools/TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm 2020-06-04 19:00:32 UTC (rev 262551)
+++ branches/safari-609-branch/Tools/TestWebKitAPI/Tests/WTF/cocoa/URLExtras.mm 2020-06-04 19:00:36 UTC (rev 262552)
@@ -25,6 +25,8 @@
#import "config.h"
+#import "WTFStringUtilities.h"
+#import <wtf/URL.h>
#import <wtf/Vector.h>
#import <wtf/cocoa/NSURLExtras.h>
#import <wtf/text/WTFString.h>
@@ -201,6 +203,9 @@
NSString *encodedHostName = WTF::encodeHostName(@"http://.com");
EXPECT_TRUE(encodedHostName == nil);
+
+ WTF::URL url2(URL(), utf16String(u"http://\u2267\u222E\uFE63"));
+ EXPECT_STREQ([[url2 absoluteString] UTF8String], "http://%E2%89%A7%E2%88%AE%EF%B9%A3");
}
TEST(WTF_URLExtras, URLExtras_Nil)