From 864216eaf710aebb28b752cc0b27c1abff3abf3a Mon Sep 17 00:00:00 2001 From: John Kingsbury <57527020+JohnKingsbury@users.noreply.github.com> Date: Fri, 2 Oct 2020 20:00:02 +0100 Subject: [PATCH 1/2] Correct URL encoding to allow web searches for FMs containing &s --- AngelLoader/Core.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/AngelLoader/Core.cs b/AngelLoader/Core.cs index 0bd79e4e1..bd2462344 100644 --- a/AngelLoader/Core.cs +++ b/AngelLoader/Core.cs @@ -1338,15 +1338,17 @@ internal static void OpenWebSearchUrl(string fmTitle) string url = Config.WebSearchUrl; if (url.IsWhiteSpace() || url.Length > 32766) return; + url = Uri.EscapeUriString(url); + int index = url.IndexOf("$TITLE$", StringComparison.OrdinalIgnoreCase); // Possible exceptions are: // ArgumentNullException (stringToEscape is null) // UriFormatException (The length of stringToEscape exceeds 32766 characters) // Those are both checked for above so we're good. - string finalUrl = Uri.EscapeUriString(index == -1 + string finalUrl = index == -1 ? url - : url.Substring(0, index) + fmTitle + url.Substring(index + "$TITLE$".Length)); + : url.Substring(0, index) + Uri.EscapeDataString(fmTitle) + url.Substring(index + "$TITLE$".Length); try { From b10439f3dae4371299828ff8eae6a8e1f2ad357c Mon Sep 17 00:00:00 2001 From: John Kingsbury <57527020+JohnKingsbury@users.noreply.github.com> Date: Fri, 2 Oct 2020 22:26:27 +0100 Subject: [PATCH 2/2] Move comment to a place that makes sense. --- AngelLoader/Core.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/AngelLoader/Core.cs b/AngelLoader/Core.cs index bd2462344..7124329d4 100644 --- a/AngelLoader/Core.cs +++ b/AngelLoader/Core.cs @@ -1338,14 +1338,14 @@ internal static void OpenWebSearchUrl(string fmTitle) string url = Config.WebSearchUrl; if (url.IsWhiteSpace() || url.Length > 32766) return; - url = Uri.EscapeUriString(url); - - int index = url.IndexOf("$TITLE$", StringComparison.OrdinalIgnoreCase); - // Possible exceptions are: // ArgumentNullException (stringToEscape is null) // UriFormatException (The length of stringToEscape exceeds 32766 characters) // Those are both checked for above so we're good. + url = Uri.EscapeUriString(url); + + int index = url.IndexOf("$TITLE$", StringComparison.OrdinalIgnoreCase); + string finalUrl = index == -1 ? url : url.Substring(0, index) + Uri.EscapeDataString(fmTitle) + url.Substring(index + "$TITLE$".Length);