// Bug 210976 - StringIndexOutOfBoundsException: String index out of range: 399 public void testIssue210976() throws ParseException { String code = "<a href=\"@&msc=@@@&klub=@@@\"></a>"; // 01234567 8901234567890123456 7890123 // 0 1 2 3 HtmlParseResult result = parse(code); Node root = result.root(); assertNotNull(root); // ElementUtils.dumpTree(root); OpenTag a = ElementUtils.query(root, "html/body/a"); assertNotNull(a); assertEquals(0, a.from()); assertEquals(29, a.to()); Attribute attr = a.getAttribute("href"); assertNotNull(attr); assertNotNull(attr.value()); assertNotNull(attr.unquotedValue()); assertEquals("\"@&msc=@@@&klub=@@@\"", attr.value()); assertEquals("@&msc=@@@&klub=@@@", attr.unquotedValue()); }
// //Bug 193268 - AssertionError: Unexpected node type ENDTAG // public void testScriptTagInBody() throws ParseException { // String scriptOpenTag = "<script type=\"text/javascript\" src=\"test.js\">"; // // 0123456789012 3456789012345678 901234 56789012 // 345678901234567890123456789 // // 0 1 2 3 4 5 // String code = "<!doctype html>" // + "<html>" // + "<head>" // + "<title></title>" // + "</head>" // + "<body>" // + "<canvas>" // + "<a/>" // + "</canvas>" // + scriptOpenTag + "</script>" // + "</body>" // + "</html>"; // //// ParseTreeBuilder.setLoggerLevel(Level.FINER); // HtmlParseResult result = parse(code); // Node root = result.root(); // // assertNotNull(root); // ElementUtils.dumpTree(root); // // OpenTag title = ElementUtils.query(root, "html/head/title"); // assertNotNull(title); // assertNotNull(title.matchingCloseTag()); // // OpenTag a = ElementUtils.query(root, "html/body/canvas/a"); // assertNotNull(a); // assertTrue(a.isEmpty()); // // OpenTag scriptOpen = ElementUtils.query(root, "html/body/script"); // assertNotNull(scriptOpen); // // assertEquals(76, scriptOpen.from()); // assertEquals(76 + 45, scriptOpen.to()); // // CloseTag scriptEnd = scriptOpen.matchingCloseTag(); // assertNotNull(scriptEnd); // // assertEquals(121, scriptEnd.from()); // assertEquals(130, scriptEnd.to()); // // } // [Bug 195103] Refactoring changes a changed filename incorrectly in the html <script> tag public void testIsAttributeQuoted() throws ParseException { String code = "<!doctype html>" + "<html>" + "<head>" + "<title></title>" + "</head>" + "<body>" + "<div onclick=\"alert()\">x</div>" + "<p onclick='alert()'>x</p>" + "<a onclick=alert>x</a>" + "</body>" + "</html>"; HtmlParseResult result = parse(code); Node root = result.root(); assertNotNull(root); // NodeUtils.dumpTree(root); OpenTag div = ElementUtils.query(root, "html/body/div"); assertNotNull(div); Attribute attr = div.getAttribute("onclick"); assertNotNull(attr); assertTrue(attr.isValueQuoted()); OpenTag p = ElementUtils.query(root, "html/body/p"); assertNotNull(p); attr = p.getAttribute("onclick"); assertNotNull(attr); assertTrue(attr.isValueQuoted()); OpenTag a = ElementUtils.query(root, "html/body/a"); assertNotNull(a); attr = a.getAttribute("onclick"); assertNotNull(attr); assertFalse(attr.isValueQuoted()); }
public void testParseTagAttributeWithoutValue() throws ParseException { String code = "<!doctype html><body><div align/></body>"; HtmlParseResult result = parse(code); Node root = result.root(); assertNotNull(root); // ElementUtils.dumpTree(root); OpenTag div = ElementUtils.query(root, "html/body/div"); assertNotNull(div); Attribute attr = div.getAttribute("align"); assertNotNull(attr); assertNull(attr.value()); assertNull(attr.unquotedValue()); }