Skip to content

Commit

Permalink
Merge pull request #61 from JohnKingsbury/master
Browse files Browse the repository at this point in the history
Correct URL encoding to allow web searches for FMs containing &s
  • Loading branch information
FenPhoenix authored Oct 3, 2020
2 parents 35414db + b10439f commit 2ffe134
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions AngelLoader/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1338,15 +1338,17 @@ internal static void OpenWebSearchUrl(string fmTitle)
string url = Config.WebSearchUrl;
if (url.IsWhiteSpace() || url.Length > 32766) return;

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
url = Uri.EscapeUriString(url);

int index = url.IndexOf("$TITLE$", StringComparison.OrdinalIgnoreCase);

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
{
Expand Down

0 comments on commit 2ffe134

Please sign in to comment.