Title: [167211] trunk
Revision
167211
Author
da...@apple.com
Date
2014-04-13 23:58:29 -0700 (Sun, 13 Apr 2014)

Log Message

userVisibleString should not try to "encode" host names
https://bugs.webkit.org/show_bug.cgi?id=131587
rdar://problem/14686849

Reviewed by Alexey Proskuryakov.

Source/WebCore:

* WebCore.exp.in: Updated for WebCoreNSURLExtras argument type changes.

* platform/mac/WebCoreNSURLExtras.h: Removed unneeded code to make this
Objective-C++ header compile in plain C++ files, which we never need to do.
Added missing argument name, baseURL, and changed mysterious CFIndex arguments
to the correct type, CFURLComponentType.

* platform/mac/WebCoreNSURLExtras.mm:
(WebCore::isLookalikeCharacter): Removed the inline keyword from this, and added
more lookalike characters from the Mozilla list referenced here.
(WebCore::URLByTruncatingOneCharacterBeforeComponent): Updated argument type.
(WebCore::dataForURLComponentType): Ditto.
(WebCore::userVisibleString): Only call mapHostNames if host name decoding is
needed; no encoding here.

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Added URLExtras.mm.

* TestWebKitAPI/Tests/mac/URLExtras.mm: Added. A few tests for WebCoreNSURLExtras.
Coverage is tiny at this point; we could add a lot more cases!

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (167210 => 167211)


--- trunk/Source/WebCore/ChangeLog	2014-04-14 06:55:15 UTC (rev 167210)
+++ trunk/Source/WebCore/ChangeLog	2014-04-14 06:58:29 UTC (rev 167211)
@@ -1,5 +1,28 @@
 2014-04-13  Darin Adler  <da...@apple.com>
 
+        userVisibleString should not try to "encode" host names
+        https://bugs.webkit.org/show_bug.cgi?id=131587
+        rdar://problem/14686849
+
+        Reviewed by Alexey Proskuryakov.
+
+        * WebCore.exp.in: Updated for WebCoreNSURLExtras argument type changes.
+
+        * platform/mac/WebCoreNSURLExtras.h: Removed unneeded code to make this
+        Objective-C++ header compile in plain C++ files, which we never need to do.
+        Added missing argument name, baseURL, and changed mysterious CFIndex arguments
+        to the correct type, CFURLComponentType.
+
+        * platform/mac/WebCoreNSURLExtras.mm:
+        (WebCore::isLookalikeCharacter): Removed the inline keyword from this, and added
+        more lookalike characters from the Mozilla list referenced here.
+        (WebCore::URLByTruncatingOneCharacterBeforeComponent): Updated argument type.
+        (WebCore::dataForURLComponentType): Ditto.
+        (WebCore::userVisibleString): Only call mapHostNames if host name decoding is
+        needed; no encoding here.
+
+2014-04-13  Darin Adler  <da...@apple.com>
+
         REGRESSION (r158617): Find on Page can get stuck in a loop when the search string occurs in an <input> in a <fieldset>
         https://bugs.webkit.org/show_bug.cgi?id=126322
 

Modified: trunk/Source/WebCore/WebCore.exp.in (167210 => 167211)


--- trunk/Source/WebCore/WebCore.exp.in	2014-04-14 06:55:15 UTC (rev 167210)
+++ trunk/Source/WebCore/WebCore.exp.in	2014-04-14 06:58:29 UTC (rev 167211)
@@ -945,7 +945,7 @@
 __ZN7WebCore23AuthenticationChallenge23setAuthenticationClientEPNS_20AuthenticationClientE
 __ZN7WebCore23AuthenticationChallengeC1ERKNS_15ProtectionSpaceERKNS_10CredentialEjRKNS_16ResourceResponseERKNS_13ResourceErrorE
 __ZN7WebCore23SynchronousLoaderClient24platformBadResponseErrorEv
-__ZN7WebCore23dataForURLComponentTypeEP5NSURLl
+__ZN7WebCore23dataForURLComponentTypeEP5NSURL18CFURLComponentType
 __ZN7WebCore23decodeHostNameWithRangeEP8NSString8_NSRange
 __ZN7WebCore23encodeHostNameWithRangeEP8NSString8_NSRange
 __ZN7WebCore23getFileModificationTimeERKN3WTF6StringERl
@@ -1017,7 +1017,7 @@
 __ZN7WebCore3macERKNS_10CredentialE
 __ZN7WebCore3macERKNS_23AuthenticationChallengeE
 __ZN7WebCore40restrictMinimumScaleFactorToViewportSizeERNS_18ViewportAttributesENS_7IntSizeEf
-__ZN7WebCore42URLByTruncatingOneCharacterBeforeComponentEP5NSURLl
+__ZN7WebCore42URLByTruncatingOneCharacterBeforeComponentEP5NSURL18CFURLComponentType
 __ZN7WebCore47attributedStringByStrippingAttachmentCharactersEP18NSAttributedString
 __ZN7WebCore4Font11setCodePathENS0_8CodePathE
 __ZN7WebCore4Font18shouldUseSmoothingEv

Modified: trunk/Source/WebCore/platform/mac/WebCoreNSURLExtras.h (167210 => 167211)


--- trunk/Source/WebCore/platform/mac/WebCoreNSURLExtras.h	2014-04-14 06:55:15 UTC (rev 167210)
+++ trunk/Source/WebCore/platform/mac/WebCoreNSURLExtras.h	2014-04-14 06:58:29 UTC (rev 167211)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2007, 2012 Apple, Inc.  All rights reserved.
+ * Copyright (C) 2005, 2007, 2012, 2014 Apple, Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,21 +26,14 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <objc/objc.h>
-
-#ifdef __OBJC__
 @class NSString;
 @class NSURL;
-#else
-OBJC_CLASS(NSString);
-OBJC_CLASS(NSURL);
-#endif
 
 namespace WebCore {
 
 NSString *userVisibleString(NSURL *);
 NSURL *URLByCanonicalizingURL(NSURL *);
-NSURL *URLWithUserTypedString(NSString *, NSURL *);
+NSURL *URLWithUserTypedString(NSString *, NSURL *baseURL);
 NSURL *URLByRemovingUserInfo(NSURL *);
 BOOL hostNameNeedsDecodingWithRange(NSString *, NSRange);
 BOOL hostNameNeedsEncodingWithRange(NSString *, NSRange);
@@ -48,10 +41,10 @@
 NSString *encodeHostNameWithRange(NSString *, NSRange);
 NSString *decodeHostName(NSString *);
 NSString *encodeHostName(NSString *);
-NSURL *URLByTruncatingOneCharacterBeforeComponent(NSURL *, CFIndex);
+NSURL *URLByTruncatingOneCharacterBeforeComponent(NSURL *, CFURLComponentType);
 NSURL *URLWithData(NSData *, NSURL *baseURL);
 NSData *originalURLData(NSURL *);
-NSData *dataForURLComponentType(NSURL *, CFIndex);
+NSData *dataForURLComponentType(NSURL *, CFURLComponentType);
 
 NSRange rangeOfURLScheme(NSString *);
 BOOL isUserVisibleURL(NSString *);

Modified: trunk/Source/WebCore/platform/mac/WebCoreNSURLExtras.mm (167210 => 167211)


--- trunk/Source/WebCore/platform/mac/WebCoreNSURLExtras.mm	2014-04-14 06:55:15 UTC (rev 167210)
+++ trunk/Source/WebCore/platform/mac/WebCoreNSURLExtras.mm	2014-04-14 06:58:29 UTC (rev 167211)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2005, 2007, 2014 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -55,48 +55,95 @@
 
 namespace WebCore {
 
-static inline BOOL isLookalikeCharacter(int charCode)
+static BOOL isLookalikeCharacter(UChar32 charCode)
 {
     // This function treats the following as unsafe, lookalike characters:
-    // any non-printable character, any character considered as whitespace that isn't already converted to a space by ICU, 
+    // any non-printable character, any character considered as whitespace,
     // any ignorable character, and emoji characters related to locks.
     
-    // We also considered the characters in Mozilla's blacklist (http://kb.mozillazine.org/Network.IDN.blacklist_chars), 
-    // and included all of these characters that ICU can encode.
+    // We also considered the characters in Mozilla's blacklist <http://kb.mozillazine.org/Network.IDN.blacklist_chars>.
+
+    // Some of the characters here will never appear once ICU has encoded.
+    // For example, ICU transforms most spaces into an ASCII space and most
+    // slashes into an ASCII solidus. But one of the two callers uses this
+    // on characters that have not been processed by ICU, so they are needed here.
     
     if (!u_isprint(charCode) || u_isUWhiteSpace(charCode) || u_hasBinaryProperty(charCode, UCHAR_DEFAULT_IGNORABLE_CODE_POINT))
         return YES;
     
     switch (charCode) {
+        case 0x00BC: /* VULGAR FRACTION ONE QUARTER */
+        case 0x00BD: /* VULGAR FRACTION ONE HALF */
+        case 0x00BE: /* VULGAR FRACTION THREE QUARTERS */
         case 0x00ED: /* LATIN SMALL LETTER I WITH ACUTE */
         case 0x01C3: /* LATIN LETTER RETROFLEX CLICK */
         case 0x0251: /* LATIN SMALL LETTER ALPHA */
         case 0x0261: /* LATIN SMALL LETTER SCRIPT G */
+        case 0x02D0: /* MODIFIER LETTER TRIANGULAR COLON */
         case 0x0335: /* COMBINING SHORT STROKE OVERLAY */
         case 0x0337: /* COMBINING SHORT SOLIDUS OVERLAY */
         case 0x0338: /* COMBINING LONG SOLIDUS OVERLAY */
+        case 0x0589: /* ARMENIAN FULL STOP */
         case 0x05B4: /* HEBREW POINT HIRIQ */
         case 0x05BC: /* HEBREW POINT DAGESH OR MAPIQ */
         case 0x05C3: /* HEBREW PUNCTUATION SOF PASUQ */
         case 0x05F4: /* HEBREW PUNCTUATION GERSHAYIM */
+        case 0x0609: /* ARABIC-INDIC PER MILLE SIGN */
+        case 0x060A: /* ARABIC-INDIC PER TEN THOUSAND SIGN */
         case 0x0660: /* ARABIC INDIC DIGIT ZERO */
+        case 0x066A: /* ARABIC PERCENT SIGN */
         case 0x06D4: /* ARABIC FULL STOP */
         case 0x06F0: /* EXTENDED ARABIC INDIC DIGIT ZERO */
+        case 0x0701: /* SYRIAC SUPRALINEAR FULL STOP */
+        case 0x0702: /* SYRIAC SUBLINEAR FULL STOP */
+        case 0x0703: /* SYRIAC SUPRALINEAR COLON */
+        case 0x0704: /* SYRIAC SUBLINEAR COLON */
+        case 0x1735: /* PHILIPPINE SINGLE PUNCTUATION */
+        case 0x2024: /* ONE DOT LEADER */
         case 0x2027: /* HYPHENATION POINT */
         case 0x2039: /* SINGLE LEFT-POINTING ANGLE QUOTATION MARK */
         case 0x203A: /* SINGLE RIGHT-POINTING ANGLE QUOTATION MARK */
+        case 0x2041: /* CARET INSERTION POINT */
         case 0x2044: /* FRACTION SLASH */
+        case 0x2052: /* COMMERCIAL MINUS SIGN */
+        case 0x2153: /* VULGAR FRACTION ONE THIRD */
+        case 0x2154: /* VULGAR FRACTION TWO THIRDS */
+        case 0x2155: /* VULGAR FRACTION ONE FIFTH */
+        case 0x2156: /* VULGAR FRACTION TWO FIFTHS */
+        case 0x2157: /* VULGAR FRACTION THREE FIFTHS */
+        case 0x2158: /* VULGAR FRACTION FOUR FIFTHS */
+        case 0x2159: /* VULGAR FRACTION ONE SIXTH */
+        case 0x215A: /* VULGAR FRACTION FIVE SIXTHS */
+        case 0x215B: /* VULGAR FRACTION ONE EIGHT */
+        case 0x215C: /* VULGAR FRACTION THREE EIGHTHS */
+        case 0x215D: /* VULGAR FRACTION FIVE EIGHTHS */
+        case 0x215E: /* VULGAR FRACTION SEVEN EIGHTHS */
+        case 0x215F: /* FRACTION NUMERATOR ONE */
         case 0x2215: /* DIVISION SLASH */
         case 0x2216: /* SET MINUS */
+        case 0x2236: /* RATIO */
         case 0x233F: /* APL FUNCTIONAL SYMBOL SLASH BAR */
         case 0x23AE: /* INTEGRAL EXTENSION */
         case 0x244A: /* OCR DOUBLE BACKSLASH */
         case 0x2571: /* BOX DRAWINGS LIGHT DIAGONAL UPPER RIGHT TO LOWER LEFT */
         case 0x2572: /* BOX DRAWINGS LIGHT DIAGONAL UPPER LEFT TO LOWER RIGHT */
+        case 0x29F6: /* SOLIDUS WITH OVERBAR */
         case 0x29F8: /* BIG SOLIDUS */
-        case 0x29f6: /* SOLIDUS WITH OVERBAR */
         case 0x2AFB: /* TRIPLE SOLIDUS BINARY RELATION */
         case 0x2AFD: /* DOUBLE SOLIDUS OPERATOR */
+        case 0x2FF0: /* IDEOGRAPHIC DESCRIPTION CHARACTER LEFT TO RIGHT */
+        case 0x2FF1: /* IDEOGRAPHIC DESCRIPTION CHARACTER ABOVE TO BELOW */
+        case 0x2FF2: /* IDEOGRAPHIC DESCRIPTION CHARACTER LEFT TO MIDDLE AND RIGHT */
+        case 0x2FF3: /* IDEOGRAPHIC DESCRIPTION CHARACTER ABOVE TO MIDDLE AND BELOW */
+        case 0x2FF4: /* IDEOGRAPHIC DESCRIPTION CHARACTER FULL SURROUND */
+        case 0x2FF5: /* IDEOGRAPHIC DESCRIPTION CHARACTER SURROUND FROM ABOVE */
+        case 0x2FF6: /* IDEOGRAPHIC DESCRIPTION CHARACTER SURROUND FROM BELOW */
+        case 0x2FF7: /* IDEOGRAPHIC DESCRIPTION CHARACTER SURROUND FROM LEFT */
+        case 0x2FF8: /* IDEOGRAPHIC DESCRIPTION CHARACTER SURROUND FROM UPPER LEFT */
+        case 0x2FF9: /* IDEOGRAPHIC DESCRIPTION CHARACTER SURROUND FROM UPPER RIGHT */
+        case 0x2FFA: /* IDEOGRAPHIC DESCRIPTION CHARACTER SURROUND FROM LOWER LEFT */
+        case 0x2FFB: /* IDEOGRAPHIC DESCRIPTION CHARACTER OVERLAID */
+        case 0x3002: /* IDEOGRAPHIC FULL STOP */
         case 0x3008: /* LEFT ANGLE BRACKET */
         case 0x3014: /* LEFT TORTOISE SHELL BRACKET */
         case 0x3015: /* RIGHT TORTOISE SHELL BRACKET */
@@ -104,12 +151,21 @@
         case 0x3035: /* VERTICAL KANA REPEAT MARK LOWER HALF */
         case 0x321D: /* PARENTHESIZED KOREAN CHARACTER OJEON */
         case 0x321E: /* PARENTHESIZED KOREAN CHARACTER O HU */
+        case 0x33AE: /* SQUARE RAD OVER S */
+        case 0x33AF: /* SQUARE RAD OVER S SQUARED */
+        case 0x33C6: /* SQUARE C OVER KG */
         case 0x33DF: /* SQUARE A OVER M */
+        case 0xA789: /* MODIFIER LETTER COLON */
         case 0xFE14: /* PRESENTATION FORM FOR VERTICAL SEMICOLON */
         case 0xFE15: /* PRESENTATION FORM FOR VERTICAL EXCLAMATION MARK */
         case 0xFE3F: /* PRESENTATION FORM FOR VERTICAL LEFT ANGLE BRACKET */
         case 0xFE5D: /* SMALL LEFT TORTOISE SHELL BRACKET */
         case 0xFE5E: /* SMALL RIGHT TORTOISE SHELL BRACKET */
+        case 0xFF0E: /* FULLWIDTH FULL STOP */
+        case 0xFF0F: /* FULL WIDTH SOLIDUS */
+        case 0xFF61: /* HALFWIDTH IDEOGRAPHIC FULL STOP */
+        case 0xFFFC: /* OBJECT REPLACEMENT CHARACTER */
+        case 0xFFFD: /* REPLACEMENT CHARACTER */
         case 0x1F50F: /* LOCK WITH INK PEN */
         case 0x1F510: /* CLOSED LOCK WITH KEY */
         case 0x1F511: /* KEY */
@@ -516,12 +572,12 @@
     return trimmed;
 }
 
-NSURL *URLByTruncatingOneCharacterBeforeComponent(NSURL *URL, CFIndex component)
+NSURL *URLByTruncatingOneCharacterBeforeComponent(NSURL *URL, CFURLComponentType component)
 {
     if (!URL)
         return nil;
     
-    CFRange fragRg = CFURLGetByteRangeForComponent((CFURLRef)URL, static_cast<CFURLComponentType>(component), NULL);
+    CFRange fragRg = CFURLGetByteRangeForComponent((CFURLRef)URL, component, NULL);
     if (fragRg.location == kCFNotFound)
         return URL;
     
@@ -573,7 +629,7 @@
         if (!result)
             result = CFBridgingRelease(CFURLCreateAbsoluteURLWithBytes(NULL, bytes, length, kCFStringEncodingISOLatin1, (CFURLRef)baseURL, YES));
     } else
-            result = [NSURL URLWithString:@""];
+        result = [NSURL URLWithString:@""];
                 
     return result;
 }
@@ -625,7 +681,7 @@
 
 #define completeURL (CFURLComponentType)-1
 
-NSData *dataForURLComponentType(NSURL *URL, CFIndex componentType)
+NSData *dataForURLComponentType(NSURL *URL, CFURLComponentType componentType)
 {
     static int URLComponentTypeBufferLength = 2048;
     
@@ -641,7 +697,7 @@
     
     CFRange range;
     if (componentType != completeURL) {
-        range = CFURLGetByteRangeForComponent((CFURLRef)URL, static_cast<CFURLComponentType>(componentType), NULL);
+        range = CFURLGetByteRangeForComponent((CFURLRef)URL, componentType, NULL);
         if (range.location == kCFNotFound)
             return nil;
     } else {
@@ -799,7 +855,7 @@
     const unsigned char *before = static_cast<const unsigned char*>([data bytes]);
     int length = [data length];
     
-    bool needsHostNameDecoding = false;
+    bool mayNeedHostNameDecoding = false;
     
     const unsigned char *p = before;
     int bufferLength = (length * 3) + 1;
@@ -824,8 +880,8 @@
             *q++ = c;
             
             // Check for "xn--" in an efficient, non-case-sensitive, way.
-            if (c == '-' && i >= 3 && !needsHostNameDecoding && (q[-4] | 0x20) == 'x' && (q[-3] | 0x20) == 'n' && q[-2] == '-')
-                needsHostNameDecoding = true;
+            if (c == '-' && i >= 3 && !mayNeedHostNameDecoding && (q[-4] | 0x20) == 'x' && (q[-3] | 0x20) == 'n' && q[-2] == '-')
+                mayNeedHostNameDecoding = true;
         }
     }
     *q = '\0';
@@ -858,7 +914,8 @@
     
     free(after);
     
-    result = mapHostNames(result, !needsHostNameDecoding);
+    if (mayNeedHostNameDecoding)
+        result = mapHostNames(result, NO);
     result = [result precomposedStringWithCanonicalMapping];
     return CFBridgingRelease(createStringWithEscapedUnsafeCharacters((CFStringRef)result));
 }

Modified: trunk/Tools/ChangeLog (167210 => 167211)


--- trunk/Tools/ChangeLog	2014-04-14 06:55:15 UTC (rev 167210)
+++ trunk/Tools/ChangeLog	2014-04-14 06:58:29 UTC (rev 167211)
@@ -1,3 +1,16 @@
+2014-04-13  Darin Adler  <da...@apple.com>
+
+        userVisibleString should not try to "encode" host names
+        https://bugs.webkit.org/show_bug.cgi?id=131587
+        rdar://problem/14686849
+
+        Reviewed by Alexey Proskuryakov.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Added URLExtras.mm.
+
+        * TestWebKitAPI/Tests/mac/URLExtras.mm: Added. A few tests for WebCoreNSURLExtras.
+        Coverage is tiny at this point; we could add a lot more cases!
+
 2014-04-13  Jaehun Lim  <ljaehun....@samsung.com>
 
         Use #include instead of #import

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (167210 => 167211)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2014-04-14 06:55:15 UTC (rev 167210)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2014-04-14 06:58:29 UTC (rev 167211)
@@ -129,6 +129,7 @@
 		93A427A9180D9B0700CD24D7 /* RefPtr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93A427A8180D9B0700CD24D7 /* RefPtr.cpp */; };
 		93A427AB180DA26400CD24D7 /* Ref.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93A427AA180DA26400CD24D7 /* Ref.cpp */; };
 		93A720E618F1A0E800A848E1 /* CalculationValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93A720E518F1A0E800A848E1 /* CalculationValue.cpp */; };
+		93A7EB3D18FA63A4009E7670 /* URLExtras.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93A7EB3C18FA63A4009E7670 /* URLExtras.mm */; };
 		93ABA80916DDAB91002DB2FA /* StringHasher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93ABA80816DDAB91002DB2FA /* StringHasher.cpp */; };
 		93AF4ECE1506F064007FD57E /* NewFirstVisuallyNonEmptyLayoutForImages_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93AF4ECD1506F064007FD57E /* NewFirstVisuallyNonEmptyLayoutForImages_Bundle.cpp */; };
 		93AF4ED01506F123007FD57E /* lots-of-images.html in Resources */ = {isa = PBXBuildFile; fileRef = 93AF4ECF1506F123007FD57E /* lots-of-images.html */; };
@@ -460,6 +461,7 @@
 		93A427AC180DA60F00CD24D7 /* MoveOnly.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MoveOnly.h; sourceTree = "<group>"; };
 		93A427AD180DA60F00CD24D7 /* RefLogger.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RefLogger.h; sourceTree = "<group>"; };
 		93A720E518F1A0E800A848E1 /* CalculationValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CalculationValue.cpp; sourceTree = "<group>"; };
+		93A7EB3C18FA63A4009E7670 /* URLExtras.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = URLExtras.mm; sourceTree = "<group>"; };
 		93ABA80816DDAB91002DB2FA /* StringHasher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringHasher.cpp; sourceTree = "<group>"; };
 		93AF4ECA1506F035007FD57E /* NewFirstVisuallyNonEmptyLayoutForImages.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFirstVisuallyNonEmptyLayoutForImages.cpp; sourceTree = "<group>"; };
 		93AF4ECD1506F064007FD57E /* NewFirstVisuallyNonEmptyLayoutForImages_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFirstVisuallyNonEmptyLayoutForImages_Bundle.cpp; sourceTree = "<group>"; };
@@ -987,6 +989,7 @@
 				939BFE3918E5548900883275 /* StringTruncator.mm */,
 				37A6895D148A9B50005100FA /* SubresourceErrorCrash.mm */,
 				E490296714E2E3A4002BEDD1 /* TypingStyleCrash.mm */,
+				93A7EB3C18FA63A4009E7670 /* URLExtras.mm */,
 				51FBBB4C1513D4E900822738 /* WebViewCanPasteURL.mm */,
 				C2EB2DD116CAC7AC009B52EE /* WebViewDidCreateJavaScriptContext.mm */,
 				37E38C33169B7D010084C28C /* WebViewDidRemoveFrameFromHierarchy.mm */,
@@ -1305,6 +1308,7 @@
 				F6B7BE9417469209008A3445 /* DidAssociateFormControls.cpp in Sources */,
 				BC3C4C7F14587AA60025FB62 /* WKBrowsingContextGroupTest.mm in Sources */,
 				BC3C4C7214575B6A0025FB62 /* WKBrowsingContextLoadDelegateTest.mm in Sources */,
+				93A7EB3D18FA63A4009E7670 /* URLExtras.mm in Sources */,
 				51E93017156B13E1004C99DF /* WKPageGetScaleFactorNotZero.cpp in Sources */,
 				BC7B61AA129A038700D174A4 /* WKPreferences.cpp in Sources */,
 				BC90995E12567BC100083756 /* WKString.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/mac/URLExtras.mm (0 => 167211)


--- trunk/Tools/TestWebKitAPI/Tests/mac/URLExtras.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/URLExtras.mm	2014-04-14 06:58:29 UTC (rev 167211)
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#import <WebCore/WebCoreNSURLExtras.h>
+
+namespace TestWebKitAPI {
+
+static NSData *literalAsData(const char* literal)
+{
+    return [NSData dataWithBytes:literal length:strlen(literal)];
+}
+
+static const char* dataAsString(NSData *data)
+{
+    static char buffer[1000];
+    if ([data length] > sizeof(buffer) - 1)
+        return "ERROR";
+    if (memchr([data bytes], 0, [data length]))
+        return "ERROR";
+    memcpy(buffer, [data bytes], [data length]);
+    buffer[[data length]] = '\0';
+    return buffer;
+}
+
+static const char* originalDataAsString(NSURL *URL)
+{
+    return dataAsString(WebCore::originalURLData(URL));
+}
+
+static const char* userVisibleString(NSURL *URL)
+{
+    return [WebCore::userVisibleString(URL) UTF8String];
+}
+
+static NSURL *literalURL(const char* literal)
+{
+    return WebCore::URLWithData(literalAsData(literal), nil);
+}
+
+TEST(WebCore, URLExtras)
+{
+    EXPECT_STREQ("http://site.com", originalDataAsString(literalURL("http://site.com")));
+    EXPECT_STREQ("http://%77ebsite.com", originalDataAsString(literalURL("http://%77ebsite.com")));
+
+    EXPECT_STREQ("http://site.com", userVisibleString(literalURL("http://site.com")));
+    EXPECT_STREQ("http://%77ebsite.com", userVisibleString(literalURL("http://%77ebsite.com")));
+}
+
+TEST(WebCore, URLExtras_DivisionSign)
+{
+    // Selected the division sign as an example of a non-ASCII character that is allowed in host names, since it's a lookalike character.
+
+    // Code path similar to the one used when typing in a URL.
+    EXPECT_STREQ("http://site.xn--comothersite-kjb.org", originalDataAsString(WebCore::URLWithUserTypedString(@"http://site.com\xC3\xB7othersite.org", nil)));
+    EXPECT_STREQ("http://site.com\xC3\xB7othersite.org", userVisibleString(WebCore::URLWithUserTypedString(@"http://site.com\xC3\xB7othersite.org", nil)));
+
+    // Code paths similar to the ones used for URLs found in webpages or HTTP responses.
+    EXPECT_STREQ("http://site.com\xC3\xB7othersite.org", originalDataAsString(literalURL("http://site.com\xC3\xB7othersite.org")));
+    EXPECT_STREQ("http://site.com\xC3\xB7othersite.org", userVisibleString(literalURL("http://site.com\xC3\xB7othersite.org")));
+    EXPECT_STREQ("http://site.com%C3%B7othersite.org", originalDataAsString(literalURL("http://site.com%C3%B7othersite.org")));
+    EXPECT_STREQ("http://site.com\xC3\xB7othersite.org", userVisibleString(literalURL("http://site.com%C3%B7othersite.org")));
+
+    // Separate functions that deal with just a host name on its own.
+    EXPECT_STREQ("site.xn--comothersite-kjb.org", [WebCore::encodeHostName(@"site.com\xC3\xB7othersite.org") UTF8String]);
+    EXPECT_STREQ("site.com\xC3\xB7othersite.org", [WebCore::decodeHostName(@"site.com\xC3\xB7othersite.org") UTF8String]);
+}
+
+TEST(WebCore, URLExtras_Solidus)
+{
+    // Selected full width solidus, which looks like the solidus, which is the character that indicates the end of the host name.
+
+    // Code path similar to the one used when typing in a URL.
+    EXPECT_STREQ("http://site.com/othersite.org", originalDataAsString(WebCore::URLWithUserTypedString(@"http://site.com\xEF\xBC\x8Fothersite.org", nil)));
+    EXPECT_STREQ("http://site.com/othersite.org", userVisibleString(WebCore::URLWithUserTypedString(@"http://site.com\xEF\xBC\x8Fothersite.org", nil)));
+
+    // Code paths similar to the ones used for URLs found in webpages or HTTP responses.
+    EXPECT_STREQ("http://site.com\xEF\xBC\x8Fothersite.org", originalDataAsString(literalURL("http://site.com\xEF\xBC\x8Fothersite.org")));
+    EXPECT_STREQ("http://site.com%EF%BC%8Fothersite.org", userVisibleString(literalURL("http://site.com\xEF\xBC\x8Fothersite.org")));
+    EXPECT_STREQ("http://site.com%EF%BC%8Fothersite.org", originalDataAsString(literalURL("http://site.com%EF%BC%8Fothersite.org")));
+    EXPECT_STREQ("http://site.com%EF%BC%8Fothersite.org", userVisibleString(literalURL("http://site.com%EF%BC%8Fothersite.org")));
+
+    // Separate functions that deal with just a host name on its own.
+    EXPECT_STREQ("site.com/othersite.org", [WebCore::encodeHostName(@"site.com\xEF\xBC\x8Fothersite.org") UTF8String]);
+    EXPECT_STREQ("site.com\xEF\xBC\x8Fothersite.org", [WebCore::decodeHostName(@"site.com\xEF\xBC\x8Fothersite.org") UTF8String]);
+}
+
+TEST(WebCore, URLExtras_Space)
+{
+    // Selected ideographic space, which looks like the ASCII space, which is not allowed unescaped.
+
+    // Code path similar to the one used when typing in a URL.
+    EXPECT_STREQ("http://site.com%20othersite.org", originalDataAsString(WebCore::URLWithUserTypedString(@"http://site.com\xE3\x80\x80othersite.org", nil)));
+    EXPECT_STREQ("http://site.com%20othersite.org", userVisibleString(WebCore::URLWithUserTypedString(@"http://site.com\xE3\x80\x80othersite.org", nil)));
+
+    // Code paths similar to the ones used for URLs found in webpages or HTTP responses.
+    EXPECT_STREQ("http://site.com\xE3\x80\x80othersite.org", originalDataAsString(literalURL("http://site.com\xE3\x80\x80othersite.org")));
+    EXPECT_STREQ("http://site.com%E3%80%80othersite.org", userVisibleString(literalURL("http://site.com\xE3\x80\x80othersite.org")));
+    EXPECT_STREQ("http://site.com%E3%80%80othersite.org", originalDataAsString(literalURL("http://site.com%E3%80%80othersite.org")));
+    EXPECT_STREQ("http://site.com%E3%80%80othersite.org", userVisibleString(literalURL("http://site.com%E3%80%80othersite.org")));
+
+    // Separate functions that deal with just a host name on its own.
+    EXPECT_STREQ("site.com othersite.org", [WebCore::encodeHostName(@"site.com\xE3\x80\x80othersite.org") UTF8String]);
+    EXPECT_STREQ("site.com\xE3\x80\x80othersite.org", [WebCore::decodeHostName(@"site.com\xE3\x80\x80othersite.org") UTF8String]);
+}
+
+} // namespace TestWebKitAPI
Property changes on: trunk/Tools/TestWebKitAPI/Tests/mac/URLExtras.mm
___________________________________________________________________

Added: svn:eol-style

_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to