Web Inspector: non-regex Local Overrides and Script Blackboxing shouldn't apply to...
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Dec 2019 09:28:21 +0000 (09:28 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Dec 2019 09:28:21 +0000 (09:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=204954

Reviewed by Joseph Pecoraro.

If `isRegex` is false, add `^` and `$` to the beginning and end of the search string to
ensure that the search string is exactly matched, not just contained within the potentially
intercepted URL.

This doesn't actually change functionality because the Web Inspector frontend wouldn't
replace the network response for these containing matches, as the frontend JavaScript
already correctly performed this logic, and would therefore `Network.interceptContinue`.

Source/JavaScriptCore:

* inspector/ContentSearchUtilities.h:
* inspector/ContentSearchUtilities.cpp:
(Inspector::ContentSearchUtilities::escapeStringForRegularExpressionSource): Added.
(Inspector::ContentSearchUtilities::createRegularExpressionForSearchString): Added.
(Inspector::ContentSearchUtilities::searchInTextByLines):
(Inspector::ContentSearchUtilities::createSearchRegexSource): Deleted.
(Inspector::ContentSearchUtilities::createSearchRegex): Deleted.
Rename functions for clarity.

* inspector/agents/InspectorDebuggerAgent.cpp:
(Inspector::InspectorDebuggerAgent::shouldBlackboxURL const):

Source/WebCore:

* inspector/agents/InspectorNetworkAgent.cpp:
(WebCore::InspectorNetworkAgent::shouldIntercept):

* inspector/agents/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMDebuggerAgent::breakOnURLIfNeeded):
* inspector/agents/InspectorPageAgent.cpp:
(WebCore::InspectorPageAgent::searchInResources):
Use renamed `ContentSearchUtilities` function.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@253246 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/ContentSearchUtilities.cpp
Source/JavaScriptCore/inspector/ContentSearchUtilities.h
Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.cpp
Source/WebCore/ChangeLog
Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.cpp
Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp
Source/WebCore/inspector/agents/InspectorPageAgent.cpp

index ba61fc2..b36ea20 100644 (file)
@@ -1,3 +1,30 @@
+2019-12-07  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: non-regex Local Overrides and Script Blackboxing shouldn't apply to scripts that just contain the URL
+        https://bugs.webkit.org/show_bug.cgi?id=204954
+
+        Reviewed by Joseph Pecoraro.
+
+        If `isRegex` is false, add `^` and `$` to the beginning and end of the search string to
+        ensure that the search string is exactly matched, not just contained within the potentially
+        intercepted URL.
+
+        This doesn't actually change functionality because the Web Inspector frontend wouldn't
+        replace the network response for these containing matches, as the frontend JavaScript
+        already correctly performed this logic, and would therefore `Network.interceptContinue`.
+
+        * inspector/ContentSearchUtilities.h:
+        * inspector/ContentSearchUtilities.cpp:
+        (Inspector::ContentSearchUtilities::escapeStringForRegularExpressionSource): Added.
+        (Inspector::ContentSearchUtilities::createRegularExpressionForSearchString): Added.
+        (Inspector::ContentSearchUtilities::searchInTextByLines):
+        (Inspector::ContentSearchUtilities::createSearchRegexSource): Deleted.
+        (Inspector::ContentSearchUtilities::createSearchRegex): Deleted.
+        Rename functions for clarity.
+
+        * inspector/agents/InspectorDebuggerAgent.cpp:
+        (Inspector::InspectorDebuggerAgent::shouldBlackboxURL const):
+
 2019-12-06  Zan Dobersek  <zdobersek@igalia.com>
 
         [GTK][WPE] Use bmalloc's memory footprint API for JSC heap growth management
index f791406..1251043 100644 (file)
@@ -45,7 +45,7 @@ namespace ContentSearchUtilities {
 
 static const char regexSpecialCharacters[] = "[](){}+-*.,?\\^$|";
 
-static String createSearchRegexSource(const String& text)
+static String escapeStringForRegularExpressionSource(const String& text)
 {
     StringBuilder result;
 
@@ -129,9 +129,21 @@ static Ref<Protocol::GenericTypes::SearchMatch> buildObjectForSearchMatch(size_t
         .release();
 }
 
-RegularExpression createSearchRegex(const String& query, bool caseSensitive, bool isRegex)
+RegularExpression createRegularExpressionForSearchString(const String& searchString, bool caseSensitive, SearchStringType type)
 {
-    return RegularExpression { isRegex ? query : createSearchRegexSource(query), caseSensitive ? TextCaseSensitive : TextCaseInsensitive };
+    String pattern;
+    switch (type) {
+    case SearchStringType::Regex:
+        pattern = searchString;
+        break;
+    case SearchStringType::ExactString:
+        pattern = makeString('^', escapeStringForRegularExpressionSource(searchString), '$');
+        break;
+    case SearchStringType::ContainsString:
+        pattern = escapeStringForRegularExpressionSource(searchString);
+        break;
+    }
+    return RegularExpression(pattern, caseSensitive ? TextCaseSensitive : TextCaseInsensitive);
 }
 
 int countRegularExpressionMatches(const RegularExpression& regex, const String& content)
@@ -156,7 +168,8 @@ int countRegularExpressionMatches(const RegularExpression& regex, const String&
 Ref<JSON::ArrayOf<Protocol::GenericTypes::SearchMatch>> searchInTextByLines(const String& text, const String& query, const bool caseSensitive, const bool isRegex)
 {
     auto result = JSON::ArrayOf<Protocol::GenericTypes::SearchMatch>::create();
-    auto regex = ContentSearchUtilities::createSearchRegex(query, caseSensitive, isRegex);
+    auto searchStringType = isRegex ? ContentSearchUtilities::SearchStringType::Regex : ContentSearchUtilities::SearchStringType::ContainsString;
+    auto regex = ContentSearchUtilities::createRegularExpressionForSearchString(query, caseSensitive, searchStringType);
     for (const auto& match : getRegularExpressionMatchesByLines(regex, text))
         result->addItem(buildObjectForSearchMatch(match.first, match.second));
     return result;
index d2ea8ee..7e7a0ca 100644 (file)
@@ -39,7 +39,9 @@ namespace Inspector {
 
 namespace ContentSearchUtilities {
 
-JS_EXPORT_PRIVATE JSC::Yarr::RegularExpression createSearchRegex(const String& query, bool caseSensitive, bool isRegex);
+enum class SearchStringType { Regex, ExactString, ContainsString };
+JS_EXPORT_PRIVATE JSC::Yarr::RegularExpression createRegularExpressionForSearchString(const String& searchString, bool caseSensitive, SearchStringType);
+
 JS_EXPORT_PRIVATE int countRegularExpressionMatches(const JSC::Yarr::RegularExpression&, const String&);
 JS_EXPORT_PRIVATE Ref<JSON::ArrayOf<Protocol::GenericTypes::SearchMatch>> searchInTextByLines(const String& text, const String& query, const bool caseSensitive, const bool isRegex);
 JS_EXPORT_PRIVATE TextPosition textPositionFromOffset(size_t offset, const Vector<size_t>& lineEndings);
index 4468757..45cee86 100644 (file)
@@ -926,7 +926,8 @@ bool InspectorDebuggerAgent::shouldBlackboxURL(const String& url) const
 {
     if (!url.isEmpty()) {
         for (const auto& blackboxConfig : m_blackboxedURLs) {
-            auto regex = ContentSearchUtilities::createSearchRegex(blackboxConfig.url, blackboxConfig.caseSensitive, blackboxConfig.isRegex);
+            auto searchStringType = blackboxConfig.isRegex ? ContentSearchUtilities::SearchStringType::Regex : ContentSearchUtilities::SearchStringType::ExactString;
+            auto regex = ContentSearchUtilities::createRegularExpressionForSearchString(blackboxConfig.url, blackboxConfig.caseSensitive, searchStringType);
             if (regex.match(url) != -1)
                 return true;
         }
index 2a2b1d7..a6197f2 100644 (file)
@@ -1,3 +1,27 @@
+2019-12-07  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: non-regex Local Overrides and Script Blackboxing shouldn't apply to scripts that just contain the URL
+        https://bugs.webkit.org/show_bug.cgi?id=204954
+
+        Reviewed by Joseph Pecoraro.
+
+        If `isRegex` is false, add `^` and `$` to the beginning and end of the search string to
+        ensure that the search string is exactly matched, not just contained within the potentially
+        intercepted URL.
+
+        This doesn't actually change functionality because the Web Inspector frontend wouldn't
+        replace the network response for these containing matches, as the frontend JavaScript
+        already correctly performed this logic, and would therefore `Network.interceptContinue`.
+
+        * inspector/agents/InspectorNetworkAgent.cpp:
+        (WebCore::InspectorNetworkAgent::shouldIntercept):
+
+        * inspector/agents/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMDebuggerAgent::breakOnURLIfNeeded):
+        * inspector/agents/InspectorPageAgent.cpp:
+        (WebCore::InspectorPageAgent::searchInResources):
+        Use renamed `ContentSearchUtilities` function.
+
 2019-12-06  Zalan Bujtas  <zalan@apple.com>
 
         [LFC][IFC] Rename ContentBreak to ContentWrappingRule and ContentBreak::wrap to ContentWrappingRule::push
index c6dc219..4ff0040 100644 (file)
@@ -298,10 +298,10 @@ void InspectorDOMDebuggerAgent::breakOnURLIfNeeded(const String& url, URLBreakpo
     if (m_pauseOnAllURLsEnabled)
         breakpointURL = emptyString();
     else {
-        for (auto& entry : m_urlBreakpoints) {
-            const auto& query = entry.key;
-            bool isRegex = entry.value == URLBreakpointType::RegularExpression;
-            auto regex = ContentSearchUtilities::createSearchRegex(query, false, isRegex);
+        for (auto& [query, type] : m_urlBreakpoints) {
+            bool isRegex = type == URLBreakpointType::RegularExpression;
+            auto searchStringType = isRegex ? ContentSearchUtilities::SearchStringType::Regex : ContentSearchUtilities::SearchStringType::ContainsString;
+            auto regex = ContentSearchUtilities::createRegularExpressionForSearchString(query, false, searchStringType);
             if (regex.match(url) != -1) {
                 breakpointURL = query;
                 break;
index 8eed41d..ca8f169 100644 (file)
@@ -852,7 +852,8 @@ bool InspectorNetworkAgent::shouldIntercept(URL url)
         return false;
 
     for (auto& intercept : m_intercepts) {
-        auto regex = ContentSearchUtilities::createSearchRegex(intercept.url, intercept.caseSensitive, intercept.isRegex);
+        auto searchStringType = intercept.isRegex ? ContentSearchUtilities::SearchStringType::Regex : ContentSearchUtilities::SearchStringType::ExactString;
+        auto regex = ContentSearchUtilities::createRegularExpressionForSearchString(intercept.url, intercept.caseSensitive, searchStringType);
         if (regex.match(urlString) != -1)
             return true;
     }
index f2e228b..01edd00 100644 (file)
@@ -644,9 +644,11 @@ void InspectorPageAgent::searchInResources(ErrorString&, const String& text, con
 {
     result = JSON::ArrayOf<Inspector::Protocol::Page::SearchResult>::create();
 
-    bool isRegex = optionalIsRegex ? *optionalIsRegex : false;
     bool caseSensitive = optionalCaseSensitive ? *optionalCaseSensitive : false;
-    JSC::Yarr::RegularExpression regex = ContentSearchUtilities::createSearchRegex(text, caseSensitive, isRegex);
+    bool isRegex = optionalIsRegex ? *optionalIsRegex : false;
+
+    auto searchStringType = isRegex ? ContentSearchUtilities::SearchStringType::Regex : ContentSearchUtilities::SearchStringType::ContainsString;
+    auto regex = ContentSearchUtilities::createRegularExpressionForSearchString(text, caseSensitive, searchStringType);
 
     for (Frame* frame = &m_inspectedPage.mainFrame(); frame; frame = frame->tree().traverseNext()) {
         for (auto* cachedResource : cachedResourcesForFrame(frame)) {