[Htmlparser-cvs] htmlparser/src/org/htmlparser/tests/tagTests DoctypeTagTest.java,1.34,1.35 FormTagT
Brought to you by:
derrickoswald
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests In directory sc8-pr-cvs1:/tmp/cvs-serv27740/tagTests Modified Files: DoctypeTagTest.java FormTagTest.java ImageTagTest.java JspTagTest.java LinkTagTest.java Log Message: Added testcases but was unable to reproduce the following bugs in the version 1.4 codebase: 839264 toHtml() parse error in Javascripts with "form" keyword 833592 DOCTYPE element is not parsed correctly 826764 ParserException occurs only when using setInputHTML() instea 825820 Words conjoined 825645 <input> not getting parsed inside table 813838 links not parsed correctly and #851882 zero length alt tag causes bug in ImageScanner #832530 empty attribute causes parser to fail #805598 attribute src in tag img sometimes not correctly parsed (these 3 are all the same bug, duplicates of the following): #753012 IMG SRC not parsed v1.3 & v1.4 #755929 Empty string attr. value causes attr parsing to be stopped #778781 SRC-attribute suppression in IMG-tags Also reviewed these test cases, again, with none reproducible in 1.4: #788746 parser crashes on comments like <!-- foobar --!> #772700 Jsp Tags are not parsed correctly when in quoted attributes. Index: DoctypeTagTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/DoctypeTagTest.java,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** DoctypeTagTest.java 8 Dec 2003 01:31:55 -0000 1.34 --- DoctypeTagTest.java 2 Jan 2004 05:01:28 -0000 1.35 *************** *** 29,34 **** --- 29,36 ---- package org.htmlparser.tests.tagTests; + import org.htmlparser.Node; import org.htmlparser.tags.DoctypeTag; import org.htmlparser.tests.ParserTestCase; + import org.htmlparser.util.NodeIterator; import org.htmlparser.util.ParserException; *************** *** 44,48 **** } ! public void testToHTML() throws ParserException { String testHTML = new String( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">\n"+ --- 46,51 ---- } ! public void testToHTML() throws ParserException ! { String testHTML = new String( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">\n"+ *************** *** 61,64 **** --- 64,85 ---- DoctypeTag docTypeTag = (DoctypeTag)node[0]; assertStringEquals("toHTML()","<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">",docTypeTag.toHtml()); + } + + /** + * See bug #833592 DOCTYPE element is not parsed correctly + * Contributed by Trevor Watson (t007). + */ + public void DocTypeElementTest () throws ParserException + { + final String DOCTYPE = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"; + final String HTML = DOCTYPE + "\n<HTML>\n <HEAD>\n <TITLE>HTMLParserDocTypeBugTest</TITLE>\n </HEAD>\n <BODY>\n HTMLParser DOCTYPE node bug test.\n </BODY>\n</HTML>"; + + createParser(HTML); + + NodeIterator e = parser.elements(); + Node node = e.nextNode(); + + // First node is doctype + assertStringEquals("Doctype element output is incorrect.", DOCTYPE, node.toHtml()); } } Index: FormTagTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/FormTagTest.java,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** FormTagTest.java 1 Jan 2004 16:54:47 -0000 1.41 --- FormTagTest.java 2 Jan 2004 05:01:28 -0000 1.42 *************** *** 528,530 **** --- 528,571 ---- assertStringEquals ("text contents", "\n The text.\n ", texTag.getChild (0).toHtml ()); } + + /** + * From bug #825645 <input> not getting parsed inside table + */ + public void testInputInTable () throws Exception + { + FormTag formTag; + NodeList nl; + InputTag inpTag; + + String html = "<html>\n" + + "<body>\n" + + "<form action=\"/cgi-bin/test.pl\" method=\"post\">\n" + + "<table><tr><td>\n" + + "<INPUT type=hidden NAME=\"test1\" VALUE=\"insidetable\">\n" + + "</td></tr>\n" + + "</table>\n" + + "<INPUT type=hidden NAME=\"Test2\"\n" + + "VALUE=\"outsidetable\">\n" + + "<INPUT type=hidden name=\"a\" value=\"b\">\n" + + "</form>\n" + + "</body>\n" + + "</html>\n"; + createParser (html); + formTag = + (FormTag)(parser.extractAllNodesThatAre ( + FormTag.class + )[0]); + assertNotNull ("Should have found a form tag",formTag); + nl = formTag.getFormInputs (); + assertTrue ("3 inputs", 3 == nl.size ()); + inpTag = (InputTag)nl.elementAt (0); + assertStringEquals ("name", "test1", inpTag.getAttribute ("name")); + assertStringEquals ("value", "insidetable", inpTag.getAttribute ("value")); + inpTag = (InputTag)nl.elementAt (1); + assertStringEquals ("name", "Test2", inpTag.getAttribute ("name")); + assertStringEquals ("value", "outsidetable", inpTag.getAttribute ("value")); + inpTag = (InputTag)nl.elementAt (2); + assertStringEquals ("name", "a", inpTag.getAttribute ("name")); + assertStringEquals ("value", "b", inpTag.getAttribute ("value")); + } } Index: ImageTagTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/ImageTagTest.java,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** ImageTagTest.java 8 Dec 2003 01:31:55 -0000 1.39 --- ImageTagTest.java 2 Jan 2004 05:01:28 -0000 1.40 *************** *** 200,216 **** } - // see bug #778781 SRC-attribute suppression in IMG-tags - // HTML before parse: - // <img src="images/first" alt="first"> - // <img src="images/second" alt=""> - // <img alt="third" src="images/third"> - // <img alt="" src="images/fourth"> - // - // HTML after parse: - // <IMG ALT="first" SRC="images/first"> - // <IMG ALT="" SRC="images/second"> - // <IMG ALT="third" SRC="images/third"> - // <IMG ALT=""> - public void testDynamicRelativeImageScan() throws ParserException { createParser("<IMG SRC=\"../abc/def/mypic.jpg\">","http://www.yahoo.com/ghi?abcdefg"); --- 200,203 ---- Index: JspTagTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/JspTagTest.java,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** JspTagTest.java 8 Dec 2003 01:31:55 -0000 1.40 --- JspTagTest.java 2 Jan 2004 05:01:28 -0000 1.41 *************** *** 194,202 **** * See bug #772700 Jsp Tags are not parsed correctly when in quoted attributes. */ ! // public void testJspTagsInQuotedAttribes() throws ParserException ! // { ! // // this test seems to mess up.... ! // testJspTagsInAttributes("<img alt=\"<%=altText1%>\" src=\"<%=imgUrl1%>\" border=\"<%=borderToggle%>\">"); ! // } private void testJspTagsInAttributes(String html) throws ParserException --- 194,202 ---- * See bug #772700 Jsp Tags are not parsed correctly when in quoted attributes. */ ! public void testJspTagsInQuotedAttribes() throws ParserException ! { ! // this test seems to mess up.... ! testJspTagsInAttributes("<img alt=\"<%=altText1%>\" src=\"<%=imgUrl1%>\" border=\"<%=borderToggle%>\">"); ! } private void testJspTagsInAttributes(String html) throws ParserException Index: LinkTagTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/LinkTagTest.java,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** LinkTagTest.java 8 Dec 2003 01:31:55 -0000 1.43 --- LinkTagTest.java 2 Jan 2004 05:01:28 -0000 1.44 *************** *** 845,847 **** --- 845,860 ---- assertEquals("link text","<< An Empire Reborn: Chapter 2 <<",linkTag.getLinkText()); } + + /** + * See bug #813838 links not parsed correctly + */ + public void testPlainText() throws Exception + { + String html = "<a href=Cities/><b>Cities</b></a>"; + createParser (html); + parseAndAssertNodeCount (1); + assertType("node", LinkTag.class, node[0]); + LinkTag linkTag = (LinkTag)node[0]; + assertEquals ("plain text", "Cities", linkTag.toPlainTextString ()); + } } |