public void Escape(string purl, string expected) { var actual = PseudoUrl.ParsePurl(purl); TestContext.WriteLine(actual); Assert.AreEqual(expected, actual); }
public void Generic(string purl, string url, bool expected) { var sut = new PseudoUrl(purl); var match = sut.Match(url); var success = match == expected; TestContext.WriteLine($"{url} -- exp:{expected}, match:{match}"); Assert.IsTrue(success); }
public void PoopLa(string url, bool expected) { var purl = "http[s?]://[([\\w-]+\\.){0,}]💩.la/[.*]"; var sut = new PseudoUrl(purl); var match = sut.Match(url); var success = match == expected; TestContext.WriteLine($"{url} -- exp:{expected}, match:{match}"); Assert.IsTrue(success); }
public void Throws(string purl) { Assert.Throws <ArgumentException>(() => { _ = new PseudoUrl(purl); }); }
public static PseudoUrl Parse(PseudoUrl pseudoUrl, string url) { //url = "https://foobar.com:8080/hello/kitty.aspx?noob=ish#foobar2000"; //url = "https://*.com:8080/hello/kitty.aspx?noob=ish#foobar2000"; //url = "foobar.com:8080/hello/kitty.aspx?noob=ish#foobar2000"; //url = "foobar.com:8080/hello/kitty.aspx?noob=ish"; //url = "foobar.com:8080/hello/kitty.aspx?#foobar2000"; //url = "foobar.com:8080/hello/kitty.aspx"; //url = "foobar.com:8080/"; //url = "foobar.com:8080"; //url = "foobar.com"; //url = "*:8080"; //url = "*"; if (url == null) { return(null); } pseudoUrl.RawUrl = url; int pos = url.IndexOf("://"); if (pos != -1) { pseudoUrl.Scheme = url.Substring(0, pos); pseudoUrl.Scheme = pseudoUrl.Scheme.ToLowerInvariant(); url = url.Substring(pos + 3); } else { pseudoUrl.Scheme = "http"; } pos = url.IndexOf("#"); if (pos != -1) { pseudoUrl.Hash = url.Substring(pos + 1); url = url.Substring(0, pos); } pos = url.IndexOf("?"); if (pos != -1) { pseudoUrl.QueryString = url.Substring(pos + 1); url = url.Substring(0, pos); } pos = url.IndexOf("/"); if (pos != -1) { pseudoUrl.Path = url.Substring(pos); url = url.Substring(0, pos); } pos = url.IndexOf(":"); if (pos == -1) { pseudoUrl.Port = 80; pseudoUrl.Host = url; } else { pseudoUrl.Host = url.Substring(0, pos); url = url.Substring(pos + 1); pseudoUrl.Port = int.Parse(url, System.Globalization.CultureInfo.InvariantCulture); } return(pseudoUrl); }
public static PseudoUrl Parse(string url) { PseudoUrl pseudoUrl = new PseudoUrl(); return(Parse(pseudoUrl, url)); }