Title: [195650] trunk
Revision
195650
Author
[email protected]
Date
2016-01-26 19:05:49 -0800 (Tue, 26 Jan 2016)

Log Message

Source/WebKit2:
Implement wildcard matching for plug-in policy host.
https://bugs.webkit.org/show_bug.cgi?id=153090

Patch by I-Ting Liu <[email protected]> on 2016-01-26
Reviewed by Darin Adler.

WebPlatformStrategies decides the plug-in load policy for a host by looking
for a matched hostname in the list of plug-in policies sent by Safari. This
patch adds support for wildcard matching -- if there's a policy with hostname
"*.example.com," the policy for "foo.example.com" would be replaced with that
of "*.example.com" if there's no policy for this hostname. If there is more
than one wildcard hostname, the host with the longest wildcard hostname will
be used.

This patch adds a helper function in StringUtilites that matches a string to
another string, which may contain wildcard ('*') characters.

* Platform/mac/StringUtilities.h:
- Add WebKit::stringMatchesWildcardString.
- Remove #if ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC) flag so that
the compiler allows exposing StringUtilities.h.
- Add #if __OBJC__ to allow the file to be included in WebPltformStrategies.cpp

* Platform/mac/StringUtilities.mm:
(WebKit::stringMatchesWildcardString):
Return true if the entire first given String matches the second. The second string
may contain wildcard characters.
(WebKit::wildcardRegexPatternString):
Return the regex _expression_ from a wildcard string by replacing the wildcard
character ('*') with (".*") and escaping regular _expression_ metacharacters.
(WebKit::formattedPhoneNumberString):
To expose StringUtilities.h for tests, we removed #if ENABLE(TELEPHONE_NUMBER_DETECTION)
&& PLATFORM(MAC) flag in the header. Add a function that returns nil for
#if !(ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)) to fix the removal
of the flag in the header file.

* WebKit2.xcodeproj/project.pbxproj:
Change the file attribute of StringUtilities.h from Project to Private for
testing in TestWebKitAPI.

* WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
(WebKit::WebPlatformStrategies::longestMatchedWildcardHostForHost):
Return the wildcard hostname whose matched substring with the host is the longest.
(WebKit::WebPlatformStrategies::replaceHostWithMatchedWildcardHost):
Replace the look-up host with a matched wildcard host if there is a match and that
the matched wildcard host's plug-in identifier is the same as that of the host.
(WebKit::WebPlatformStrategies::pluginLoadClientPolicyForHost):
Try to replace the look-up host with the wildcard host if there's no policy for
the host. Restructure the function to reduce hashmap lookup.

* WebProcess/WebCoreSupport/WebPlatformStrategies.h:
Declare the methods.

Source/WTF:
Implement wildcard matching for plug-in policy host.
https://bugs.webkit.org/show_bug.cgi?id=153090

Patch by I-Ting Liu <[email protected]> on 2016-01-26
Reviewed by Darin Adler.

* wtf/text/AtomicString.h:
(WTF::AtomicString::AtomicString):
Add __bridge to allow compilation.

Tools:
Add a test for WebKit::stringMatchesWildcardString.
https://bugs.webkit.org/show_bug.cgi?id=153090

Patch by I-Ting Liu <[email protected]> on 2016-01-26
Reviewed by Darin Adler.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
Add the file to the project.

* TestWebKitAPI/Tests/WebKit2/mac/StringUtilities.mm: Added.
(TestWebKitAPI::TEST):
Test that a string matches another string that may contain wildcard characters.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (195649 => 195650)


--- trunk/Source/WTF/ChangeLog	2016-01-27 02:41:55 UTC (rev 195649)
+++ trunk/Source/WTF/ChangeLog	2016-01-27 03:05:49 UTC (rev 195650)
@@ -1,3 +1,14 @@
+2016-01-26  I-Ting Liu  <[email protected]>
+
+        Implement wildcard matching for plug-in policy host.
+        https://bugs.webkit.org/show_bug.cgi?id=153090
+
+        Reviewed by Darin Adler.
+
+        * wtf/text/AtomicString.h:
+        (WTF::AtomicString::AtomicString):
+        Add __bridge to allow compilation.
+
 2016-01-26  Joseph Pecoraro  <[email protected]>
 
         Generalize ResourceUsageData gathering to be used outside of ResourceUsageOverlay

Modified: trunk/Source/WTF/wtf/text/AtomicString.h (195649 => 195650)


--- trunk/Source/WTF/wtf/text/AtomicString.h	2016-01-27 02:41:55 UTC (rev 195649)
+++ trunk/Source/WTF/wtf/text/AtomicString.h	2016-01-27 03:05:49 UTC (rev 195650)
@@ -297,7 +297,7 @@
 
 #ifdef __OBJC__
 inline AtomicString::AtomicString(NSString* s)
-    : m_string(AtomicStringImpl::add((CFStringRef)s))
+    : m_string(AtomicStringImpl::add((__bridge CFStringRef)s))
 {
 }
 #endif

Modified: trunk/Source/WebKit2/ChangeLog (195649 => 195650)


--- trunk/Source/WebKit2/ChangeLog	2016-01-27 02:41:55 UTC (rev 195649)
+++ trunk/Source/WebKit2/ChangeLog	2016-01-27 03:05:49 UTC (rev 195650)
@@ -1,3 +1,57 @@
+2016-01-26  I-Ting Liu  <[email protected]>
+
+        Implement wildcard matching for plug-in policy host.
+        https://bugs.webkit.org/show_bug.cgi?id=153090
+
+        Reviewed by Darin Adler.
+
+        WebPlatformStrategies decides the plug-in load policy for a host by looking
+        for a matched hostname in the list of plug-in policies sent by Safari. This
+        patch adds support for wildcard matching -- if there's a policy with hostname
+        "*.example.com," the policy for "foo.example.com" would be replaced with that
+        of "*.example.com" if there's no policy for this hostname. If there is more
+        than one wildcard hostname, the host with the longest wildcard hostname will
+        be used.
+
+        This patch adds a helper function in StringUtilites that matches a string to
+        another string, which may contain wildcard ('*') characters.
+
+        * Platform/mac/StringUtilities.h:
+        - Add WebKit::stringMatchesWildcardString.
+        - Remove #if ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC) flag so that
+        the compiler allows exposing StringUtilities.h.
+        - Add #if __OBJC__ to allow the file to be included in WebPltformStrategies.cpp
+
+        * Platform/mac/StringUtilities.mm:
+        (WebKit::stringMatchesWildcardString):
+        Return true if the entire first given String matches the second. The second string 
+        may contain wildcard characters.
+        (WebKit::wildcardRegexPatternString):
+        Return the regex _expression_ from a wildcard string by replacing the wildcard
+        character ('*') with (".*") and escaping regular _expression_ metacharacters.
+        (WebKit::formattedPhoneNumberString):
+        To expose StringUtilities.h for tests, we removed #if ENABLE(TELEPHONE_NUMBER_DETECTION)
+        && PLATFORM(MAC) flag in the header. Add a function that returns nil for
+        #if !(ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)) to fix the removal
+        of the flag in the header file.
+
+        * WebKit2.xcodeproj/project.pbxproj:
+        Change the file attribute of StringUtilities.h from Project to Private for
+        testing in TestWebKitAPI.
+
+        * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
+        (WebKit::WebPlatformStrategies::longestMatchedWildcardHostForHost):
+        Return the wildcard hostname whose matched substring with the host is the longest.
+        (WebKit::WebPlatformStrategies::replaceHostWithMatchedWildcardHost):
+        Replace the look-up host with a matched wildcard host if there is a match and that
+        the matched wildcard host's plug-in identifier is the same as that of the host.
+        (WebKit::WebPlatformStrategies::pluginLoadClientPolicyForHost):
+        Try to replace the look-up host with the wildcard host if there's no policy for
+        the host. Restructure the function to reduce hashmap lookup.
+
+        * WebProcess/WebCoreSupport/WebPlatformStrategies.h:
+        Declare the methods.
+
 2016-01-26  Anders Carlsson  <[email protected]>
 
         Remove -d flag from make invocation.

Modified: trunk/Source/WebKit2/Platform/mac/StringUtilities.h (195649 => 195650)


--- trunk/Source/WebKit2/Platform/mac/StringUtilities.h	2016-01-27 02:41:55 UTC (rev 195649)
+++ trunk/Source/WebKit2/Platform/mac/StringUtilities.h	2016-01-27 03:05:49 UTC (rev 195650)
@@ -26,18 +26,22 @@
 #ifndef StringUtilities_h
 #define StringUtilities_h
 
+#import <WebKit/WKDeclarationSpecifiers.h>
 #import <wtf/Forward.h>
 
 namespace WebKit {
 
+#ifdef __OBJC__
+
 // NOTE: This does not use String::operator NSString*() since that function
 // expects to be called on the thread running WebCore.
 NSString *nsStringFromWebCoreString(const String&);
-
-#if ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)
 NSString *formattedPhoneNumberString(NSString *originalPhoneNumber);
-#endif
 
+#endif // defined(__OBJC__)
+
+WK_EXPORT bool stringMatchesWildcardString(const String& stringToBeMatched, const String& wildcardString);
+
 }
 
 #endif // StringUtilities_h

Modified: trunk/Source/WebKit2/Platform/mac/StringUtilities.mm (195649 => 195650)


--- trunk/Source/WebKit2/Platform/mac/StringUtilities.mm	2016-01-27 02:41:55 UTC (rev 195649)
+++ trunk/Source/WebKit2/Platform/mac/StringUtilities.mm	2016-01-27 03:05:49 UTC (rev 195650)
@@ -30,7 +30,8 @@
 #import "WKStringCF.h"
 #import <WebCore/SoftLinking.h>
 #import <wtf/ObjcRuntimeExtras.h>
-#import <wtf/text/WTFString.h>
+#import <wtf/text/StringBuilder.h>
+#import <yarr/RegularExpression.h>
 
 namespace WebKit {
 
@@ -39,6 +40,34 @@
     return string.isEmpty() ? @"" : CFBridgingRelease(WKStringCopyCFString(0, toAPI(string.impl())));
 }
 
+static String wildcardRegexPatternString(const String& string)
+{
+    String metaCharacters = ".|+?()[]{}^$";
+    UChar escapeCharacter = '\\';
+    UChar wildcardCharacter = '*';
+
+    StringBuilder stringBuilder;
+
+    stringBuilder.append('^');
+    for (unsigned i = 0; i < string.length(); i++) {
+        auto character = string[i];
+        if (metaCharacters.contains(character) || character == escapeCharacter)
+            stringBuilder.append(escapeCharacter);
+        else if (character == wildcardCharacter)
+            stringBuilder.append('.');
+
+        stringBuilder.append(character);
+    }
+    stringBuilder.append('$');
+
+    return stringBuilder.toString();
+}
+
+bool stringMatchesWildcardString(const String& string, const String& wildcardString)
+{
+    return JSC::Yarr::RegularExpression(wildcardRegexPatternString(wildcardString), TextCaseInsensitive).match(string) != -1;
+}
+
 #if ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)
 
 SOFT_LINK_PRIVATE_FRAMEWORK(PhoneNumbers);
@@ -72,6 +101,13 @@
     return [(NSString *)phoneNumberString autorelease];
 }
 
+#else
+
+NSString *formattedPhoneNumberString(NSString *)
+{
+    return nil;
+}
+
 #endif // ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)
 
 }

Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (195649 => 195650)


--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2016-01-27 02:41:55 UTC (rev 195649)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2016-01-27 03:05:49 UTC (rev 195650)
@@ -579,7 +579,7 @@
 		293EBEAB1627D9C9005F89F1 /* WKDOMText.h in Headers */ = {isa = PBXBuildFile; fileRef = 293EBEA91627D9C9005F89F1 /* WKDOMText.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		293EBEAC1627D9C9005F89F1 /* WKDOMText.mm in Sources */ = {isa = PBXBuildFile; fileRef = 293EBEAA1627D9C9005F89F1 /* WKDOMText.mm */; };
 		29501724162A4504004A9D71 /* WKWebProcessPlugInBrowserContextControllerPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 29501723162A4504004A9D71 /* WKWebProcessPlugInBrowserContextControllerPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
-		296BD85D15019BC30071F424 /* StringUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 296BD85B15019BC30071F424 /* StringUtilities.h */; };
+		296BD85D15019BC30071F424 /* StringUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 296BD85B15019BC30071F424 /* StringUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		296BD85E15019BC30071F424 /* StringUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = 296BD85C15019BC30071F424 /* StringUtilities.mm */; };
 		2984F57C164B915F004BC0C6 /* CustomProtocolManagerProxyMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2984F57A164B915F004BC0C6 /* CustomProtocolManagerProxyMessageReceiver.cpp */; };
 		2984F57D164B915F004BC0C6 /* CustomProtocolManagerProxyMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 2984F57B164B915F004BC0C6 /* CustomProtocolManagerProxyMessages.h */; };

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp (195649 => 195650)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp	2016-01-27 02:41:55 UTC (rev 195649)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp	2016-01-27 03:05:49 UTC (rev 195650)
@@ -67,6 +67,10 @@
 #include <WebCore/URL.h>
 #include <wtf/Atomics.h>
 
+#if PLATFORM(MAC)
+#include "StringUtilities.h"
+#endif
+
 using namespace WebCore;
 
 namespace WebKit {
@@ -239,29 +243,85 @@
 
 #if ENABLE(NETSCAPE_PLUGIN_API)
 #if PLATFORM(MAC)
+
+String WebPlatformStrategies::longestMatchedWildcardHostForHost(const String& host) const
+{
+    String longestMatchedHost;
+
+    for (auto& key : m_hostsToPluginIdentifierData.keys()) {
+        if (key.contains('*') && key != "*" && stringMatchesWildcardString(host, key)) {
+            if (key.length() > longestMatchedHost.length())
+                longestMatchedHost = key;
+            else if (key.length() == longestMatchedHost.length() && codePointCompareLessThan(key, longestMatchedHost))
+                longestMatchedHost = key;
+        }
+    }
+
+    return longestMatchedHost;
+}
+
+bool WebPlatformStrategies::replaceHostWithMatchedWildcardHost(String& host, const String& identifier) const
+{
+    String matchedWildcardHost = longestMatchedWildcardHostForHost(host);
+
+    if (matchedWildcardHost.isNull())
+        return false;
+
+    auto plugInIdentifierData = m_hostsToPluginIdentifierData.find(matchedWildcardHost);
+    if (plugInIdentifierData == m_hostsToPluginIdentifierData.end() || !plugInIdentifierData->value.contains(identifier))
+        return false;
+
+    host = matchedWildcardHost;
+    return true;
+}
+
 bool WebPlatformStrategies::pluginLoadClientPolicyForHost(const String& host, const PluginInfo& info, PluginLoadClientPolicy& policy) const
 {
     String hostToLookUp = host;
-    if (!m_hostsToPluginIdentifierData.contains(hostToLookUp))
-        hostToLookUp = "*";
-    if (!m_hostsToPluginIdentifierData.contains(hostToLookUp))
+    String identifier = info.bundleIdentifier;
+
+    auto policiesByIdentifierIterator = m_hostsToPluginIdentifierData.find(hostToLookUp);
+
+    if (!identifier.isNull() && policiesByIdentifierIterator == m_hostsToPluginIdentifierData.end()) {
+        if (!replaceHostWithMatchedWildcardHost(hostToLookUp, identifier))
+            hostToLookUp = "*";
+        policiesByIdentifierIterator = m_hostsToPluginIdentifierData.find(hostToLookUp);
+        if (hostToLookUp != "*" && policiesByIdentifierIterator == m_hostsToPluginIdentifierData.end()) {
+            hostToLookUp = "*";
+            policiesByIdentifierIterator = m_hostsToPluginIdentifierData.find(hostToLookUp);
+        }
+    }
+    if (policiesByIdentifierIterator == m_hostsToPluginIdentifierData.end())
         return false;
 
-    PluginPolicyMapsByIdentifier policiesByIdentifier = m_hostsToPluginIdentifierData.get(hostToLookUp);
-    String identifier = info.bundleIdentifier;
-    if (!identifier || !policiesByIdentifier.contains(identifier))
+    auto& policiesByIdentifier = policiesByIdentifierIterator->value;
+
+    if (!identifier)
         identifier = "*";
-    if (!policiesByIdentifier.contains(identifier))
+
+    auto identifierPolicyIterator = policiesByIdentifier.find(identifier);
+    if (identifier != "*" && identifierPolicyIterator == policiesByIdentifier.end()) {
+        identifier = "*";
+        identifierPolicyIterator = policiesByIdentifier.find(identifier);
+    }
+    if (identifierPolicyIterator == policiesByIdentifier.end())
         return false;
 
-    PluginLoadClientPoliciesByBundleVersion versionsToPolicies = policiesByIdentifier.get(identifier);
+    auto& versionsToPolicies = identifierPolicyIterator->value;
+
     String version = info.versionString;
-    if (!version || !versionsToPolicies.contains(version))
+    if (!version)
         version = "*";
-    if (!versionsToPolicies.contains(version))
+    auto policyIterator = versionsToPolicies.find(version);
+    if (version != "*" && policyIterator == versionsToPolicies.end()) {
+        version = "*";
+        policyIterator = versionsToPolicies.find(version);
+    }
+
+    if (policyIterator == versionsToPolicies.end())
         return false;
 
-    policy = versionsToPolicies.get(version);
+    policy = policyIterator->value;
     return true;
 }
 #endif // PLATFORM(MAC)

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h (195649 => 195650)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h	2016-01-27 02:41:55 UTC (rev 195649)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebPlatformStrategies.h	2016-01-27 03:05:49 UTC (rev 195650)
@@ -112,6 +112,8 @@
 #if PLATFORM(MAC)
     HashMap<String, PluginPolicyMapsByIdentifier> m_hostsToPluginIdentifierData;
     bool pluginLoadClientPolicyForHost(const String&, const WebCore::PluginInfo&, WebCore::PluginLoadClientPolicy&) const;
+    String longestMatchedWildcardHostForHost(const String& host) const;
+    bool replaceHostWithMatchedWildcardHost(String& host, const String& identifier) const;
 #endif // PLATFORM(MAC)
 #endif // ENABLE(NETSCAPE_PLUGIN_API)
 };

Modified: trunk/Tools/ChangeLog (195649 => 195650)


--- trunk/Tools/ChangeLog	2016-01-27 02:41:55 UTC (rev 195649)
+++ trunk/Tools/ChangeLog	2016-01-27 03:05:49 UTC (rev 195650)
@@ -1,3 +1,17 @@
+2016-01-26  I-Ting Liu  <[email protected]>
+
+        Add a test for WebKit::stringMatchesWildcardString.
+        https://bugs.webkit.org/show_bug.cgi?id=153090
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        Add the file to the project.
+
+        * TestWebKitAPI/Tests/WebKit2/mac/StringUtilities.mm: Added.
+        (TestWebKitAPI::TEST):
+        Test that a string matches another string that may contain wildcard characters.
+
 2016-01-26  Konstantin Tokarev  <[email protected]>
 
         [webkitdirs] Removed check for bison, gperf, and flex.

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (195649 => 195650)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-01-27 02:41:55 UTC (rev 195649)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-01-27 03:05:49 UTC (rev 195650)
@@ -260,6 +260,7 @@
 		7CCE7F4F1A411BA400447C4C /* RetainPtrHashing.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0991C50143C7D68007998F2 /* RetainPtrHashing.cpp */; };
 		7CEFA9661AC0B9E200B910FD /* _WKUserContentExtensionStore.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7CEFA9641AC0B9E200B910FD /* _WKUserContentExtensionStore.mm */; };
 		7CFBCAE51743238F00B2BFCF /* WillLoad_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */; };
+		83CF1C301C4F1B8B00688447 /* StringUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = 83CF1C2C1C4F19AE00688447 /* StringUtilities.mm */; };
 		930AD402150698D00067970F /* lots-of-text.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 930AD401150698B30067970F /* lots-of-text.html */; };
 		9361002914DC95A70061379D /* lots-of-iframes.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9361002814DC957B0061379D /* lots-of-iframes.html */; };
 		93AF4ECE1506F064007FD57E /* NewFirstVisuallyNonEmptyLayoutForImages_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93AF4ECD1506F064007FD57E /* NewFirstVisuallyNonEmptyLayoutForImages_Bundle.cpp */; };
@@ -628,6 +629,7 @@
 		7CFBCADD1743234F00B2BFCF /* WillLoad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillLoad.cpp; sourceTree = "<group>"; };
 		7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillLoad_Bundle.cpp; sourceTree = "<group>"; };
 		81B50192140F232300D9EB58 /* StringBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringBuilder.cpp; sourceTree = "<group>"; };
+		83CF1C2C1C4F19AE00688447 /* StringUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StringUtilities.mm; sourceTree = "<group>"; };
 		86BD19971A2DB05B006DCF0A /* RefCounter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RefCounter.cpp; sourceTree = "<group>"; };
 		8A2C750D16CED9550024F352 /* ResizeWindowAfterCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ResizeWindowAfterCrash.cpp; sourceTree = "<group>"; };
 		8A3AF93A16C9ED2700D248C1 /* ReloadPageAfterCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReloadPageAfterCrash.cpp; sourceTree = "<group>"; };
@@ -1449,6 +1451,7 @@
 				C0C5D3BC14598B6F00A802A6 /* GetBackingScaleFactor.mm */,
 				C0C5D3BD14598B6F00A802A6 /* GetBackingScaleFactor_Bundle.mm */,
 				1AEF994817A09F5300998EF0 /* GetPIDAfterAbortedProcessLaunch.cpp */,
+				83CF1C2C1C4F19AE00688447 /* StringUtilities.mm */,
 			);
 			path = mac;
 			sourceTree = "<group>";
@@ -1740,6 +1743,7 @@
 				7CCE7F411A411B8E00447C4C /* RefPtr.cpp in Sources */,
 				7CCE7F0D1A411AE600447C4C /* ReloadPageAfterCrash.cpp in Sources */,
 				7CCE7EC91A411A7E00447C4C /* RenderedImageFromDOMNode.mm in Sources */,
+				83CF1C301C4F1B8B00688447 /* StringUtilities.mm in Sources */,
 				7CCE7ECA1A411A7E00447C4C /* RenderedImageFromDOMRange.mm in Sources */,
 				51CD1C6C1B38CE4300142CA5 /* ModalAlerts.mm in Sources */,
 				0FFC45A61B73EBEB0085BD62 /* Lock.cpp in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/mac/StringUtilities.mm (0 => 195650)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/mac/StringUtilities.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/mac/StringUtilities.mm	2016-01-27 03:05:49 UTC (rev 195650)
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 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
+ * 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 <WebKit/StringUtilities.h>
+#import <wtf/text/WTFString.h>
+
+namespace TestWebKitAPI {
+
+TEST(WebKit2, WildcardStringMatching)
+{
+    String wildcardString = "a*b";
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString("aaaabb", "a*b"));
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString("ab", wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("ba", wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("", wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("a", wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("b", wildcardString));
+
+    wildcardString = "aabb";
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString("aabb", wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("a*b", wildcardString));
+
+    wildcardString = "*apple*";
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString("freshapple", wildcardString));
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString("applefresh", wildcardString));
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString("freshapplefresh", wildcardString));
+
+    wildcardString = "a*b*c";
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString("aabbcc", wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("bca", wildcardString));
+
+    wildcardString = "*.example*.com/*";
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString("food.examplehello.com/", wildcardString));
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString("food.example.com/bar.html", wildcardString));
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString("foo.bar.example.com/hello?query#fragment.html", wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("food.example.com", wildcardString));
+
+    wildcardString = "a*b.b*c";
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString("aabb.bbcc", wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("aabbcbbcc", wildcardString));
+
+    wildcardString = "a+b";
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString("a+b", wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("ab", wildcardString));
+
+    wildcardString = "(a*)b aa";
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString("(aaa)b aa", wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("aab aa", wildcardString));
+
+    wildcardString = "a|c";
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString("a|c", wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("abc", wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("a", wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("c", wildcardString));
+
+    wildcardString = "(a+|b)*";
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString("(a+|b)acca", "(a+|b)*"));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("ab", "(a+|b)*"));
+
+    wildcardString = "a[-]?c";
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString("a[-]?c", wildcardString));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("ac", wildcardString));
+
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("hello", "^hello$"));
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString(" ", " "));
+    EXPECT_TRUE(WebKit::stringMatchesWildcardString("^$", "^$"));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("a", "a{1}"));
+
+    // stringMatchesWildcardString should only match the entire string.
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("aabbaabb", "aabb"));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("aabb\naabb", "aabb"));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("bab", "a*"));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("bab", "*a"));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("bab", "a*b"));
+    EXPECT_FALSE(WebKit::stringMatchesWildcardString("abcd", "b*c"));
+}
+
+}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to