public void TestForcedExitOfInfiniteLoopReadsDuringUrlDetection(UrlDetectorOptions flags)
        {
            var sourceText = " :u ";             // previously, without character read count logic, this string kills loop in UrlDetector.ReadDefault()
            var links      = new UrlDetector(sourceText, flags)
                             .Detect();

            Assert.Empty(links);
        }
        public void TestSingleLevelDomainUrlWithPortDetectionAfterMultipleColons(UrlDetectorOptions flags)
        {
            var sourceText = " l:url(https://test:8080/test "; // previously, without character read count logic, this string kills loop in UrlDetector.ReadDefault()
            var links      = new UrlDetector(sourceText, flags)
                                                               // BEWARE THE INFINITE LOOP THAT HAPPENS HERE:
                             .Detect();

            Assert.True(true);                          // Just want to confirm that we made it past the infinite loop
        }
        public void TestTextDomaniUrlDetectionAfterMultipleColons(UrlDetectorOptions flags)
        {
            var sourceText = " l:url(https://mytest.com/test ";
            var links      = new UrlDetector(sourceText, flags).Detect();

            Assert.Single(links);
            Assert.Equal("https", links[0].GetScheme());
            Assert.Equal("mytest.com", links[0].GetHost());
        }
 /// <summary>
 /// Creates a new instance of the DomainNameReader object.
 /// @param reader The input stream to read.
 /// @param buffer The string buffer to use for storing a domain name.
 /// @param current The current string that was thought to be a domain name.
 /// @param options The detector options of this reader.
 /// @param characterHandler The handler to call on each non-matching character to count matching quotes and stuff.
 /// </summary>
 public DomainNameReader(
     InputTextReader reader,
     StringBuilder buffer,
     string current,
     UrlDetectorOptions options,
     //CharacterHandler characterHandler
     Action <char> characterHandler
     )
 {
     _buffer           = buffer;
     _current          = current;
     _reader           = reader;
     _options          = options;
     _characterHandler = characterHandler;
 }
Beispiel #5
0
        /// <summary>
        /// Creates a new UrlDetector object used to find urls inside of text.
        /// @param content The content to search inside of.
        /// @param options The UrlDetectorOptions to use when detecting the content.
        /// </summary>
        /// <param name="content"></param>
        /// <param name="options"></param>
        /// <param name="validSchemes"></param>
        public UrlDetector(string content, UrlDetectorOptions options, HashSet <string> validSchemes = null)
        {
            _reader  = new InputTextReader(content);
            _options = options;

            if (validSchemes == null || validSchemes.Count == 0)
            {
                validSchemes = new HashSet <string>
                {
                    "http", "https", "ftp", "ftps"
                }
            }
            ;

            SetValidSchemes(validSchemes);
        }
        private void RunTest(string text, UrlDetectorOptions options, params string[] expected)
        {
            //do the detection
            var parser     = new UrlDetector(text, options);
            var found      = parser.Detect();
            var foundArray = new string[found.Count];

            for (var i = 0; i < foundArray.Length; i++)
            {
                foundArray[i] = found[i].GetOriginalUrl();
            }

            // All expected items found, ordering irrelevant
            var areSame = !expected.Except(foundArray).Any() && expected.Length == foundArray.Length;

            Assert.True(areSame);
        }