Skip to content

Commit

Permalink
Fixes unintended unescaping of urls (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
zumoshi committed Oct 20, 2017
1 parent 4e1ddcf commit c60b9a3
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion BrowserSelect/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
Expand All @@ -19,6 +20,8 @@ static class Program
[STAThread]
static void Main(string[] args)
{
// fix #28
LeaveDotsAndSlashesEscaped();
// to prevent loss of settings when on update
if (Settings.Default.UpdateSettings)
{
Expand Down Expand Up @@ -46,7 +49,7 @@ static void Main(string[] args)
url = args[0];
//add http:// to url if it is missing a protocol
var uri = new UriBuilder(url).Uri;
url = uri.ToString();
url = uri.AbsoluteUri;

foreach (var sr in Settings.Default.AutoBrowser.Cast<string>()
// maybe i should use a better way to split the pattern and browser name ?
Expand Down Expand Up @@ -182,5 +185,26 @@ public static bool DoesWildcardMatch(string originalString, string searchString)
return regex.IsMatch(originalString);
}

// https://stackoverflow.com/a/7202560/1461004
private static void LeaveDotsAndSlashesEscaped()
{
var getSyntaxMethod =
typeof(UriParser).GetMethod("GetSyntax", BindingFlags.Static | BindingFlags.NonPublic);
if (getSyntaxMethod == null)
{
throw new MissingMethodException("UriParser", "GetSyntax");
}

var uriParser = getSyntaxMethod.Invoke(null, new object[] { "http" });

var setUpdatableFlagsMethod =
uriParser.GetType().GetMethod("SetUpdatableFlags", BindingFlags.Instance | BindingFlags.NonPublic);
if (setUpdatableFlagsMethod == null)
{
throw new MissingMethodException("UriParser", "SetUpdatableFlags");
}

setUpdatableFlagsMethod.Invoke(uriParser, new object[] { 0 });
}
}
}

0 comments on commit c60b9a3

Please sign in to comment.