Ejemplo n.º 1
0
        public void Escape(string purl, string expected)
        {
            var actual = PseudoUrl.ParsePurl(purl);

            TestContext.WriteLine(actual);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public void Throws(string purl)
 {
     Assert.Throws <ArgumentException>(() => { _ = new PseudoUrl(purl); });
 }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        public static PseudoUrl Parse(string url)
        {
            PseudoUrl pseudoUrl = new PseudoUrl();

            return(Parse(pseudoUrl, url));
        }