Ejemplo n.º 1
0
        public void ReadAttrName()
        {
            string         input;
            StringReader   sr;
            HtmlTextReader reader;
            string         output;

            // no whitespace
            input  = "class='red' ";
            sr     = new StringReader(input);
            reader = new HtmlTextReader(sr);
            output = reader.ReadAttributeName();
            Assert.AreEqual("class", output);
            Assert.AreEqual('=', (char)reader.Peek());
            Assert.AreEqual(ParseState.AttributeValue, reader.ParseState);

            // whitespace
            input  = "   class='red' ";
            sr     = new StringReader(input);
            reader = new HtmlTextReader(sr);
            output = reader.ReadAttributeName();
            Assert.AreEqual("class", output);
            Assert.AreEqual('=', (char)reader.Peek());

            // whitespace
            input  = "   class   = 'red' ";
            sr     = new StringReader(input);
            reader = new HtmlTextReader(sr);
            output = reader.ReadAttributeName();
            Assert.AreEqual("class", output);
            Assert.AreEqual(' ', (char)reader.Peek());

            // whitespace
            input  = "   class   = \"red\" ";
            sr     = new StringReader(input);
            reader = new HtmlTextReader(sr);
            output = reader.ReadAttributeName();
            Assert.AreEqual("class", output);
            Assert.AreEqual(' ', (char)reader.Peek());

            // missing attr. the rest is val
            input  = "   =red foo=bar ";
            sr     = new StringReader(input);
            reader = new HtmlTextReader(sr);
            output = reader.ReadAttributeName();
            Assert.AreEqual("=red", output);
            Assert.AreEqual(' ', (char)reader.Peek());
        }
Ejemplo n.º 2
0
        public void ReadQuotedAttribute()
        {
            string         input;
            HtmlTextReader reader;
            string         output;

            // Ensure we parse to end of single quotes...
            input  = " ='abc'  ";
            reader = new HtmlTextReader(new StringReader(input));
            output = reader.ReadAttributeValue();
            Assert.AreEqual("abc", output);

            // Ensure we parse to end of double quotes...
            input  = " =\"abc\"  ";
            reader = new HtmlTextReader(new StringReader(input));
            output = reader.ReadAttributeValue();
            Assert.AreEqual("abc", output);

            // Ignore double quotes in the middle
            input  = " ='abc\"def'  ";
            reader = new HtmlTextReader(new StringReader(input));
            output = reader.ReadAttributeValue();
            Assert.AreEqual("abc\"def", output);

            // Ignore end tag in the middle of quotes
            input  = " ='abc>def'  ";
            reader = new HtmlTextReader(new StringReader(input));
            output = reader.ReadAttributeValue();
            Assert.AreEqual("abc>def", output);

            // Parse until end of string with open quote
            input  = "= 'abcdef ";
            reader = new HtmlTextReader(new StringReader(input));
            output = reader.ReadAttributeValue();
            Assert.AreEqual("abcdef ", output);

            // Parse until end of string with open quote
            input  = "= \"abcdef ";
            reader = new HtmlTextReader(new StringReader(input));
            output = reader.ReadAttributeValue();
            Assert.AreEqual("abcdef ", output);

            // Not checking whitespace inside quotes
            input  = " =\"abcdef ";
            reader = new HtmlTextReader(new StringReader(input));
            output = reader.ReadAttributeValue();
            Assert.AreEqual("abcdef ", output);

            // Ignore single quotes in the middle of double quotes
            input  = " =\"abc'def\" ";
            reader = new HtmlTextReader(new StringReader(input));
            output = reader.ReadAttributeValue();
            Assert.AreEqual("abc'def", output);

            // Ignore end tag in the middle of quotes
            input  = " =\"abc>def\" ";
            reader = new HtmlTextReader(new StringReader(input));
            output = reader.ReadAttributeValue();
            Assert.AreEqual("abc>def", output);

            // Ensure we don't consume the >.
            input = "  ='abcdef'>";
            StringReader sr = new StringReader(input);

            reader = new HtmlTextReader(sr);
            output = reader.ReadAttributeValue();
            Assert.AreEqual("abcdef", output);
            Assert.AreEqual('>', (char)reader.Peek());
        }
Ejemplo n.º 3
0
        public void ReadUnquotedAttribute()
        {
            string         input;
            HtmlTextReader reader;
            string         output;

            // no whitespace
            input  = "=abc";
            reader = new HtmlTextReader(new StringReader(input));
            output = reader.ReadAttributeValue();
            Assert.AreEqual("abc", output);

            // Starting whitespace
            input  = "  =abc";
            reader = new HtmlTextReader(new StringReader(input));
            output = reader.ReadAttributeValue();
            Assert.AreEqual("abc", output);

            // Starting whitespace
            input  = "  \t\n\r=abc";
            reader = new HtmlTextReader(new StringReader(input));
            output = reader.ReadAttributeValue();
            Assert.AreEqual("abc", output);

            // Ending whitespace
            input  = "=abc  ";
            reader = new HtmlTextReader(new StringReader(input));
            output = reader.ReadAttributeValue();
            Assert.AreEqual("abc", output);

            // Whitespace start and end
            input  = "  = abc  ";
            reader = new HtmlTextReader(new StringReader(input));
            output = reader.ReadAttributeValue();
            Assert.AreEqual("abc", output);

            // Whitespace start and end
            input  = "  =\t\n\rabc \n\r";
            reader = new HtmlTextReader(new StringReader(input));
            output = reader.ReadAttributeValue();
            Assert.AreEqual("abc", output);

            // Whitespace end tag in the middle. Ensure
            // we don't consume the char.
            input = "=  abc>def  ";
            StringReader sr = new StringReader(input);

            reader = new HtmlTextReader(sr);
            output = reader.ReadAttributeValue();
            Assert.AreEqual("abc", output);
            Assert.AreEqual('d', (char)reader.Peek());
            Assert.AreEqual(ParseState.Text, reader.ParseState);

            // Ensure we don't consume the last space.
            input  = "  =abcdef ";
            sr     = new StringReader(input);
            reader = new HtmlTextReader(sr);
            output = reader.ReadAttributeValue();
            Assert.AreEqual("abcdef", output);
            Assert.AreEqual(' ', (char)reader.Peek());
        }