From e0f731b2331a94623f0aa9a6a17454b717258c43 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Tue, 20 Jan 2015 21:11:07 +0100 Subject: [PATCH] Optimize URL detection * Do not detect "http://" as URL any more * Limit supported protocols to fixed list (as Microsoft does) * Support "mailto:" prefix Signed-off-by: Sven Strickroth --- src/TortoiseProc/AppUtils.cpp | 7 +++++-- src/Utils/MiscUI/SciEdit.cpp | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/TortoiseProc/AppUtils.cpp b/src/TortoiseProc/AppUtils.cpp index 501685fcf..4302c2f1f 100644 --- a/src/TortoiseProc/AppUtils.cpp +++ b/src/TortoiseProc/AppUtils.cpp @@ -930,8 +930,11 @@ namespace { { if (!PathIsURLW(sText)) return false; - if (sText.Find(L"://") >= 0) - return true; + for (const CString& prefix : { L"http://", L"https://", L"git://", L"ftp://", L"file://", L"mailto:" }) + { + if (sText.Find(prefix) == 0 && sText.GetLength() != prefix.GetLength()) + return true; + } return false; } } diff --git a/src/Utils/MiscUI/SciEdit.cpp b/src/Utils/MiscUI/SciEdit.cpp index aba61d119..ab5c2972e 100644 --- a/src/Utils/MiscUI/SciEdit.cpp +++ b/src/Utils/MiscUI/SciEdit.cpp @@ -1480,8 +1480,11 @@ bool CSciEdit::IsUrl(const CStringA& sText) { if (!PathIsURLA(sText)) return false; - if (sText.Find("://")>=0) - return true; + for (const CStringA& prefix : { "http://", "https://", "git://", "ftp://", "file://", "mailto:" }) + { + if (sText.Find(prefix) == 0 && sText.GetLength() != prefix.GetLength()) + return true; + } return false; } -- 2.11.4.GIT