[Htmlparser-cvs] htmlparser/src/org/htmlparser/tests/tagTests JspTagTest.java,1.43,1.44
Brought to you by:
derrickoswald
From: <der...@pr...> - 2004-01-26 13:44:45
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3286/tests/tagTests Modified Files: JspTagTest.java Log Message: Fix bug #880283 Character ">" erroneously inserted by Lexer. Some jsp tags are now handled in a separate jsp parse in the lexer. Jsp tags embedded as attributes are still not handled. Refer to bug #772700 Jsp Tags are not parsed correctly when in quoted attributes, which is now reversed (i.e. in quotes are OK, outside of quotes causes problems), but this points out a deficiency in the data structure holding tag contents (attribute lists) that doesn't provide for tags within attributes. Index: JspTagTest.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/JspTagTest.java,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** JspTagTest.java 14 Jan 2004 02:53:47 -0000 1.43 --- JspTagTest.java 24 Jan 2004 17:14:47 -0000 1.44 *************** *** 43,47 **** private static final boolean JSP_TESTS_ENABLED = false; ! public JspTagTest(String name) { super(name); } --- 43,48 ---- private static final boolean JSP_TESTS_ENABLED = false; ! public JspTagTest(String name) ! { super(name); } *************** *** 66,105 **** public void testJspTag() throws ParserException { ! if (JSP_TESTS_ENABLED) ! { ! String contents = "jsp:useBean id=\"transfer\" scope=\"session\" class=\"com.bank.PageBean\"/"; ! String jsp = "<" + contents + ">"; ! String contents2 = "%\n"+ ! " org.apache.struts.util.BeanUtils.populate(transfer, request);\n"+ ! " if(request.getParameter(\"marker\") == null)\n"+ ! " // initialize a pseudo-property\n"+ ! " transfer.set(\"days\", java.util.Arrays.asList(\n"+ ! " new String[] {\"1\", \"2\", \"3\", \"4\", \"31\"}));\n"+ ! " else \n"+ ! " if(transfer.validate(request))\n"+ ! " %"; ! createParser( ! "<%@ taglib uri=\"/WEB-INF/struts.tld\" prefix=\"struts\" %>\n"+ ! jsp + "\n" + ! "<" + contents2 + ">\n<jsp:forward page=\"transferConfirm.jsp\"/><%\n"+ ! "%>"); ! Parser.setLineSeparator("\r\n"); ! parser.setNodeFactory (new PrototypicalNodeFactory (new JspTag ())); ! parseAndAssertNodeCount(8); ! // The first node should be an JspTag ! assertTrue("Node 1 should be an JspTag",node[0] instanceof JspTag); ! JspTag tag = (JspTag)node[0]; ! assertStringEquals("Contents of the tag","%@ taglib uri=\"/WEB-INF/struts.tld\" prefix=\"struts\" %",tag.getText()); ! // The second node should be a normal tag ! assertTrue("Node 3 should be a normal Tag",node[2] instanceof Tag); ! Tag htag = (Tag)node[2]; ! assertStringEquals("Contents of the tag",contents,htag.getText()); ! assertStringEquals("html",jsp,htag.toHtml()); ! // The third node should be an JspTag ! assertTrue("Node 5 should be an JspTag",node[4] instanceof JspTag); ! JspTag tag2 = (JspTag)node[4]; ! assertStringEquals("Contents of the tag",contents2,tag2.getText()); ! } } --- 67,103 ---- public void testJspTag() throws ParserException { ! String contents = "jsp:useBean id=\"transfer\" scope=\"session\" class=\"com.bank.PageBean\"/"; ! String jsp = "<" + contents + ">"; ! String contents2 = "%\n"+ ! " org.apache.struts.util.BeanUtils.populate(transfer, request);\n"+ ! " if(request.getParameter(\"marker\") == null)\n"+ ! " // initialize a pseudo-property\n"+ ! " transfer.set(\"days\", java.util.Arrays.asList(\n"+ ! " new String[] {\"1\", \"2\", \"3\", \"4\", \"31\"}));\n"+ ! " else \n"+ ! " if(transfer.validate(request))\n"+ ! " %"; ! createParser( ! "<%@ taglib uri=\"/WEB-INF/struts.tld\" prefix=\"struts\" %>\n"+ ! jsp + "\n" + ! "<" + contents2 + ">\n<jsp:forward page=\"transferConfirm.jsp\"/><%\n"+ ! "%>"); ! Parser.setLineSeparator("\r\n"); ! parser.setNodeFactory (new PrototypicalNodeFactory (new JspTag ())); ! parseAndAssertNodeCount(8); ! // The first node should be a JspTag ! assertTrue("Node 1 should be a JspTag",node[0] instanceof JspTag); ! JspTag tag = (JspTag)node[0]; ! assertStringEquals("Contents of the tag","%@ taglib uri=\"/WEB-INF/struts.tld\" prefix=\"struts\" %",tag.getText()); ! // The second node should be a normal tag ! assertTrue("Node 3 should be a normal Tag",node[2] instanceof Tag); ! Tag htag = (Tag)node[2]; ! assertStringEquals("Contents of the tag",contents,htag.getText()); ! assertStringEquals("html",jsp,htag.toHtml()); ! // The third node should be an JspTag ! assertTrue("Node 5 should be an JspTag",node[4] instanceof JspTag); ! JspTag tag2 = (JspTag)node[4]; ! assertStringEquals("Contents of the tag",contents2,tag2.getText()); } *************** *** 121,169 **** * Creation date: (6/17/2001 4:01:06 PM) */ ! public void testToHTML() throws ParserException { ! if (JSP_TESTS_ENABLED) ! { ! createParser( ! "<%@ taglib uri=\"/WEB-INF/struts.tld\" prefix=\"struts\" %>\n"+ ! "<jsp:useBean id=\"transfer\" scope=\"session\" class=\"com.bank.PageBean\"/>\n"+ ! "<%\n"+ ! " org.apache.struts.util.BeanUtils.populate(transfer, request);\n"+ ! " if(request.getParameter(\"marker\") == null)\n"+ ! " // initialize a pseudo-property\n"+ ! " transfer.set(\"days\", java.util.Arrays.asList(\n"+ ! " new String[] {\"1\", \"2\", \"3\", \"4\", \"31\"}));\n"+ ! " else \n"+ ! " if(transfer.validate(request))\n"+ ! " %><jsp:forward page=\"transferConfirm.jsp\"/><%\n"+ ! "%>\n"); ! Parser.setLineSeparator("\r\n"); ! parser.setNodeFactory (new PrototypicalNodeFactory (new JspTag ())); ! parseAndAssertNodeCount(8); ! // The first node should be an JspTag ! assertTrue("Node 1 should be an JspTag",node[0] instanceof JspTag); ! JspTag tag = (JspTag)node[0]; ! assertEquals("Raw String of the first JSP tag","<%@ taglib uri=\"/WEB-INF/struts.tld\" prefix=\"struts\" %>",tag.toHtml()); ! // The third node should be an JspTag ! assertTrue("Node 5 should be an JspTag",node[5] instanceof JspTag); ! JspTag tag2 = (JspTag)node[8]; ! String expected = "<%\r\n"+ ! " org.apache.struts.util.BeanUtils.populate(transfer, request);\r\n"+ ! " if(request.getParameter(\"marker\") == null)\r\n"+ ! " // initialize a pseudo-property\r\n"+ ! " transfer.set(\"days\", java.util.Arrays.asList(\r\n"+ ! " new String[] {\"1\", \"2\", \"3\", \"4\", \"31\"}));\r\n"+ ! " else \r\n"+ ! " if(transfer.validate(request))\r\n"+ ! " %>"; ! assertEquals("Raw String of the second JSP tag",expected,tag2.toHtml()); ! assertTrue("Node 4 should be an HTMLJspTag",node[4] instanceof JspTag); ! JspTag tag4 = (JspTag)node[4]; ! expected = "<%\r\n"+ ! "%>"; ! assertEquals("Raw String of the fourth JSP tag",expected,tag4.toHtml()); ! } } --- 119,158 ---- * Creation date: (6/17/2001 4:01:06 PM) */ ! public void testToHtml () throws ParserException { ! String guts = "\n"+ ! " org.apache.struts.util.BeanUtils.populate(transfer, request);\n"+ ! " if(request.getParameter(\"marker\") == null)\n"+ ! " // initialize a pseudo-property\n"+ ! " transfer.set(\"days\", java.util.Arrays.asList(\n"+ ! " new String[] {\"1\", \"2\", \"3\", \"4\", \"31\"}));\n"+ ! " else \n"+ ! " if(transfer.validate(request))\n"+ ! " "; ! createParser( ! "<%@ taglib uri=\"/WEB-INF/struts.tld\" prefix=\"struts\" %>\n"+ ! "<jsp:useBean id=\"transfer\" scope=\"session\" class=\"com.bank.PageBean\"/>\n"+ ! "<%" + ! guts ! + "%><jsp:forward page=\"transferConfirm.jsp\"/><%\n"+ ! "%>\n"); ! Parser.setLineSeparator("\r\n"); ! parser.setNodeFactory (new PrototypicalNodeFactory (new JspTag ())); ! parseAndAssertNodeCount(8); ! // The first node should be a JspTag ! assertTrue("Node 1 should be a JspTag",node[0] instanceof JspTag); ! JspTag tag = (JspTag)node[0]; ! assertEquals("Raw String of the first JSP tag","<%@ taglib uri=\"/WEB-INF/struts.tld\" prefix=\"struts\" %>",tag.toHtml()); ! // The fifth node should be a JspTag ! assertTrue("Node 5 should be a JspTag",node[4] instanceof JspTag); ! JspTag tag2 = (JspTag)node[4]; ! String expected = "<%" + guts + "%>"; ! assertEquals("Raw String of the second JSP tag",expected,tag2.toHtml()); ! assertTrue("Node 7 should be a JspTag",node[6] instanceof JspTag); ! JspTag tag4 = (JspTag)node[6]; ! expected = "<%\n%>"; ! assertEquals("Raw String of the fourth JSP tag",expected,tag4.toHtml()); } *************** *** 183,216 **** * See bug #772700 Jsp Tags are not parsed correctly when in quoted attributes. */ ! public void testJspTagsInUnQuotedAttribes() throws ParserException { ! // this test should pass when none of the attibutes are quoted ! testJspTagsInAttributes("<img alt=<%=altText1%> src=<%=imgUrl1%> border=<%=borderToggle%>>"); ! } /** * 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 { if (JSP_TESTS_ENABLED) { ! createParser(html); ! parser.setNodeFactory (new PrototypicalNodeFactory (new JspTag ())); ! parseAndAssertNodeCount(7); ! assertTrue("Should be a Jsp tag but was "+node[1].getClass().getName(),node[1] instanceof JspTag); ! assertTrue("Should be a Jsp tag but was "+node[3].getClass().getName(),node[3] instanceof JspTag); ! assertTrue("Should be a Jsp tag but was "+node[5].getClass().getName(),node[5] instanceof JspTag); ! assertTrue("Text Should be '<%=altText1%>'but was '" + node[1].toHtml() + "'" ,node[1].toHtml().equals("<%=altText1%>")); ! assertTrue("Text Should be '<%=imgUrl1%>' but was '" + node[3].toHtml() + "'" ,node[3].toHtml().equals("<%=imgUrl1%>")); ! assertTrue("Text Should be '<%=borderToggle%>' but was '" + node[5].toHtml() + "'" ,node[5].toHtml().equals("<%=borderToggle%>")); } } } --- 172,209 ---- * See bug #772700 Jsp Tags are not parsed correctly when in quoted attributes. */ ! public void testJspTagsInUnQuotedAttribes() throws ParserException ! { ! // this test should pass when none of the attibutes are quoted ! if (JSP_TESTS_ENABLED) ! testJspTagsInAttributes("<img alt=<%=altText1%> src=<%=imgUrl1%> border=<%=borderToggle%>>"); ! } /** * 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 { + createParser (html); + parser.setNodeFactory (new PrototypicalNodeFactory (new JspTag ())); if (JSP_TESTS_ENABLED) { ! parseAndAssertNodeCount (7); ! assertTrue ("Should be a Jsp tag but was " + node[1].getClass().getName(), node[1] instanceof JspTag); ! assertTrue ("Should be a Jsp tag but was " + node[3].getClass().getName(), node[3] instanceof JspTag); ! assertTrue ("Should be a Jsp tag but was " + node[5].getClass().getName(), node[5] instanceof JspTag); ! assertTrue ("Text Should be '<%=altText1%>'but was '" + node[1].toHtml() + "'" , node[1].toHtml().equals("<%=altText1%>")); ! assertTrue ("Text Should be '<%=imgUrl1%>' but was '" + node[3].toHtml() + "'" , node[3].toHtml().equals("<%=imgUrl1%>")); ! assertTrue ("Text Should be '<%=borderToggle%>' but was '" + node[5].toHtml() + "'" , node[5].toHtml().equals("<%=borderToggle%>")); } + else + parseAndAssertNodeCount (1); } } |