Title: [253246] trunk/Source
Revision
253246
Author
[email protected]
Date
2019-12-07 01:28:21 -0800 (Sat, 07 Dec 2019)

Log Message

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`.

Source/_javascript_Core:

* 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.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (253245 => 253246)


--- trunk/Source/_javascript_Core/ChangeLog	2019-12-07 08:42:49 UTC (rev 253245)
+++ trunk/Source/_javascript_Core/ChangeLog	2019-12-07 09:28:21 UTC (rev 253246)
@@ -1,3 +1,30 @@
+2019-12-07  Devin Rousso  <[email protected]>
+
+        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  <[email protected]>
 
         [GTK][WPE] Use bmalloc's memory footprint API for JSC heap growth management

Modified: trunk/Source/_javascript_Core/inspector/ContentSearchUtilities.cpp (253245 => 253246)


--- trunk/Source/_javascript_Core/inspector/ContentSearchUtilities.cpp	2019-12-07 08:42:49 UTC (rev 253245)
+++ trunk/Source/_javascript_Core/inspector/ContentSearchUtilities.cpp	2019-12-07 09:28:21 UTC (rev 253246)
@@ -45,7 +45,7 @@
 
 static const char regexSpecialCharacters[] = "[](){}+-*.,?\\^$|";
 
-static String createSearchRegexSource(const String& text)
+static String escapeStringForRegularExpressionSource(const String& text)
 {
     StringBuilder result;
 
@@ -129,9 +129,21 @@
         .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 @@
 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;

Modified: trunk/Source/_javascript_Core/inspector/ContentSearchUtilities.h (253245 => 253246)


--- trunk/Source/_javascript_Core/inspector/ContentSearchUtilities.h	2019-12-07 08:42:49 UTC (rev 253245)
+++ trunk/Source/_javascript_Core/inspector/ContentSearchUtilities.h	2019-12-07 09:28:21 UTC (rev 253246)
@@ -39,7 +39,9 @@
 
 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);

Modified: trunk/Source/_javascript_Core/inspector/agents/InspectorDebuggerAgent.cpp (253245 => 253246)


--- trunk/Source/_javascript_Core/inspector/agents/InspectorDebuggerAgent.cpp	2019-12-07 08:42:49 UTC (rev 253245)
+++ trunk/Source/_javascript_Core/inspector/agents/InspectorDebuggerAgent.cpp	2019-12-07 09:28:21 UTC (rev 253246)
@@ -926,7 +926,8 @@
 {
     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;
         }

Modified: trunk/Source/WebCore/ChangeLog (253245 => 253246)


--- trunk/Source/WebCore/ChangeLog	2019-12-07 08:42:49 UTC (rev 253245)
+++ trunk/Source/WebCore/ChangeLog	2019-12-07 09:28:21 UTC (rev 253246)
@@ -1,3 +1,27 @@
+2019-12-07  Devin Rousso  <[email protected]>
+
+        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  <[email protected]>
 
         [LFC][IFC] Rename ContentBreak to ContentWrappingRule and ContentBreak::wrap to ContentWrappingRule::push

Modified: trunk/Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.cpp (253245 => 253246)


--- trunk/Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.cpp	2019-12-07 08:42:49 UTC (rev 253245)
+++ trunk/Source/WebCore/inspector/agents/InspectorDOMDebuggerAgent.cpp	2019-12-07 09:28:21 UTC (rev 253246)
@@ -298,10 +298,10 @@
     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;

Modified: trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp (253245 => 253246)


--- trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp	2019-12-07 08:42:49 UTC (rev 253245)
+++ trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp	2019-12-07 09:28:21 UTC (rev 253246)
@@ -852,7 +852,8 @@
         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;
     }

Modified: trunk/Source/WebCore/inspector/agents/InspectorPageAgent.cpp (253245 => 253246)


--- trunk/Source/WebCore/inspector/agents/InspectorPageAgent.cpp	2019-12-07 08:42:49 UTC (rev 253245)
+++ trunk/Source/WebCore/inspector/agents/InspectorPageAgent.cpp	2019-12-07 09:28:21 UTC (rev 253246)
@@ -644,10 +644,12 @@
 {
     result = JSON::ArrayOf<Inspector::Protocol::Page::SearchResult>::create();
 
+    bool caseSensitive = optionalCaseSensitive ? *optionalCaseSensitive : false;
     bool isRegex = optionalIsRegex ? *optionalIsRegex : false;
-    bool caseSensitive = optionalCaseSensitive ? *optionalCaseSensitive : false;
-    JSC::Yarr::RegularExpression regex = ContentSearchUtilities::createSearchRegex(text, caseSensitive, isRegex);
 
+    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)) {
             if (auto textContent = InspectorNetworkAgent::textContentForCachedResource(*cachedResource)) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to