Repository: microsoft/terminal (language: cpp)

Issue:
Can't off feature "Auto recognize URLs"
### Windows Terminal version

1.22.2281.0

### Windows build number

10.0.19045.3448

### Other Software

_No response_

### Steps to reproduce

broken features:
"experimental.detectURLs": false,

work fine:
Microsoft.WindowsTerminal_1.17.11461.0_x64.zip
Microsoft.WindowsTerminal_1.18.2681.0_x64.zip


broken:
Microsoft.WindowsTerminal_1.19.10302.0_x64.zip
...
Microsoft.WindowsTerminal_1.20.11781.0_x64.zip

latest Canary terminal-1.22.2281.0 also broken


test URL:
https://aka.ms/terminal-documentation


### Expected Behavior

recognized URLs are not highlighted

### Actual Behavior

recognized URLs is highlighted
anyway

when 
"experimental.detectURLs": false,
or
"experimental.detectURLs": true,


Discussion / hints:
This regressed in cd80f3c76496c7664ed710907d7d473f634191bc because this line got removed from the branch:
https://github.com/microsoft/terminal/blob/5651f087702d97f8c5e48db6cd4199aed8a04479/src/cascadia/TerminalCore/Terminal.cpp#L1340-L1342

The fix is to add a `_detectURLs` check here:
https://github.com/microsoft/terminal/blob/1ef497970f8409def5ac03e26ba54439d0aad4e0/src/cascadia/TerminalCore/Terminal.cpp#L1422-L1452

Fix patch:
diff --git a/src/cascadia/TerminalCore/Terminal.cpp b/src/cascadia/TerminalCore/Terminal.cpp
index a7530807d07..87236331fca 100644
--- a/src/cascadia/TerminalCore/Terminal.cpp
+++ b/src/cascadia/TerminalCore/Terminal.cpp
@@ -1425,6 +1425,11 @@ PointTree Terminal::_getPatterns(til::CoordType beg, til::CoordType end) const
         LR"(\b(?:https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|$!:,.;]*[A-Za-z0-9+&@#/%=~_|$])",
     };
 
+    if (!_detectURLs)
+    {
+        return {};
+    }
+
     auto text = ICU::UTextFromTextBuffer(_activeBuffer(), beg, end + 1);
     UErrorCode status = U_ZERO_ERROR;
     PointTree::interval_vector intervals;
diff --git a/src/cascadia/UnitTests_TerminalCore/TerminalBufferTests.cpp b/src/cascadia/UnitTests_TerminalCore/TerminalBufferTests.cpp
index 827c4da85ce..ac9841369db 100644
--- a/src/cascadia/UnitTests_TerminalCore/TerminalBufferTests.cpp
+++ b/src/cascadia/UnitTests_TerminalCore/TerminalBufferTests.cpp
@@ -607,6 +607,13 @@ void TerminalBufferTests::TestURLPatternDetection()
     constexpr auto urlStartX = BeforeStr.size();
     constexpr auto urlEndX = BeforeStr.size() + UrlStr.size() - 1;
 
+    // This is off by default; turn it on for the test.
+    auto originalDetectURLs = term->_detectURLs;
+    auto restoreDetectUrls = wil::scope_exit([&]() {
+        term->_detectURLs = originalDetectURLs;
+    });
+    term->_detectURLs = true;
+
     auto& termSm = *term->_stateMachine;
     termSm.ProcessString(fmt::format(FMT_COMPILE(L"{}{}{}"), BeforeStr, UrlStr, AfterStr));
     term->UpdatePatternsUnderLock();


Test patch: