// 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());
  }
  public void testParseFileLongerThan2048chars() throws ParseException {
    StringBuilder b = new StringBuilder();
    for (int i = 0; i < 2048 * 3; i++) {
      b.append('*');
    }

    String code =
        "<!doctype html>\n"
            + "<html>\n"
            + "<title></title>\n"
            + "<body>\n"
            + b.toString()
            + "</body>\n"
            + "</html>\n";

    //        ParseTreeBuilder.setLoggerLevel(Level.ALL);
    HtmlParseResult result = parse(code);
    Node root = result.root();

    assertNotNull(root);
    //        ElementUtils.dumpTree(root);

    OpenTag body = ElementUtils.query(result.root(), "html/body");
    assertNotNull(body);

    CloseTag bodyEnd = body.matchingCloseTag();
    assertNotNull(bodyEnd);

    assertEquals(6190, bodyEnd.from());
    assertEquals(6197, bodyEnd.to());
  }
  public void testSelfCloseTagEndOffset() throws ParseException {
    //        ParseTreeBuilder.setLoggerLevel(Level.ALL);

    String code = "<div/>text";
    //             0123456
    HtmlParseResult result = parse(code);
    Node root = result.root();

    OpenTag div = ElementUtils.query(root, "html/body/div");
    assertNotNull(div);

    assertEquals(0, div.from());
    assertEquals(6, div.to());
  }
 @Override
 public void visit(Element node) {
   OpenTag tag = (OpenTag) node;
   for (Attribute id :
       tag.attributes(
           new AttributeFilter() {
             @Override
             public boolean accepts(Attribute attribute) {
               return LexerUtils.equals(CLASS_ATTR_NAME, attribute.name(), true, true);
             }
           })) {
     processElements(id, CssElementType.CLASS, classes2files);
   }
 }
  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());
  }
  public void testDivLogicalEndAtTheEOF() throws ParseException {
    String code = "<!doctype html><div><div></div>";
    //             0123456789012345678901234567890123456789
    //                                           ^
    //        NodeTreeBuilder.DEBUG = true;
    HtmlParseResult result = parse(code);
    Node root = result.root();

    //        NodeUtils.dumpTree(root);

    // the 't' node is foster parented, so it goes to the table's parent, not table itself
    OpenTag div = ElementUtils.query(root, "html/body/div");
    assertNotNull(div);

    assertEquals(30, div.semanticEnd());

    code = "<!doctype html><div><div></</div>";
    //      0123456789012345678901234567890123456789
    //                                      ^
    //        NodeTreeBuilder.DEBUG = true;
    result = parse(code);
    root = result.root();

    //        NodeUtils.dumpTree(root);

    // the 't' node is foster parented, so it goes to the table's parent, not table itself
    div = ElementUtils.query(root, "html/body/div");
    assertNotNull(div);

    assertEquals(32, div.semanticEnd());

    code = "<!doctype html><div></";
    //        0123456789012345678901234567890123456789
    //                             ^
    //        NodeTreeBuilder.DEBUG = true;
    result = parse(code);
    root = result.root();

    //        NodeUtils.dumpTree(root);

    // the 't' node is foster parented, so it goes to the table's parent, not table itself
    div = ElementUtils.query(root, "html/body/div");
    assertNotNull(div);

    assertEquals(21, div.semanticEnd());
  }
  public void testAttributes() throws ParseException {
    HtmlParseResult result =
        parse(
            "<!DOCTYPE html><html><head><title>hello</title></head><body onclick=\"alert()\"></body></html>");
    Node root = result.root();
    //        NodeUtils.dumpTree(root);
    assertNotNull(root);
    OpenTag body = ElementUtils.query(root, "html/body");
    assertNotNull(body);

    assertEquals(1, body.attributes().size());

    Attribute attr = body.attributes().iterator().next();
    assertNotNull(attr);
    assertEquals("onclick", attr.name().toString());
    assertEquals("\"alert()\"", attr.value().toString());
  }
  //    public void testProblemsReporting() throws ParseException {
  //        HtmlParseResult result = parse("<!DOCTYPE html></section>");
  //        //                              012345678901234567890123456789
  //        //                              0         1         2
  //        Collection<ProblemDescription> problems = result.getProblems();
  //
  //        assertEquals(1, problems.size());
  //        ProblemDescription p = problems.iterator().next();
  //
  //        assertEquals(ProblemDescription.ERROR, p.getType());
  //        assertEquals("nokey", p.getKey()); //XXX fix that
  //        assertEquals("Stray end tag “section”.", p.getText());
  //        assertEquals(15, p.getFrom());
  //        assertEquals(25, p.getTo());
  //
  //    }
  public void testStyle() throws ParseException {
    String code =
        "<!DOCTYPE html>\n<style type=\"text/css\">\n@import \"resources2/ezcompik/newcss2moje.css\";\n</style>\n";
    //             0123456789012345 67890123456 7890123456 789 012345678 90123456789012345678
    // 90123456789012 345678901 23456789
    //             0         1          2          3           4          5         6          7
    //      8           9

    //        NodeTreeBuilder.DEBUG = true;
    //        NodeTreeBuilder.DEBUG_STATES = true;
    HtmlParseResult result = parse(code);
    Node root = result.root();
    assertNotNull(root);
    //        NodeUtils.dumpTree(result.root());

    OpenTag head = ElementUtils.query(root, "html/head");
    assertNotNull(head);
    assertEquals(2, head.children().size());

    Iterator<Element> itr = head.children().iterator();

    OpenTag styleOpenTag = (OpenTag) itr.next();
    assertNotNull(styleOpenTag);
    assertEquals(16, styleOpenTag.from());
    assertEquals(39, styleOpenTag.to());

    Element styleEndTag = itr.next();
    assertNotNull(styleEndTag);
    assertEquals(87, styleEndTag.from());
    assertEquals(95, styleEndTag.to());

    assertSame(styleEndTag, styleOpenTag.matchingCloseTag());
  }
  // Bug 211792
  // http://netbeans.org/bugzilla/show_bug.cgi?id=211792
  public void testIssue211792() throws ParseException {
    //        ParseTreeBuilder.setLoggerLevel(Level.ALL);

    String code = "<a href=\"\"</p>";
    //             01234567 8 901234
    //             0         1
    Node root = parse(code).root();

    //        ElementUtils.dumpTree(root);

    OpenTag a = ElementUtils.query(root, "html/body/a");
    assertNotNull(a);

    Collection<Attribute> attrs = a.attributes();
    assertNotNull(attrs);

    //        for(Attribute attr : attrs) {
    //            System.out.println("from:" + attr.from());
    //            System.out.println("to:" + attr.to());
    //            System.out.println("nameoffset:" + attr.nameOffset());
    //            System.out.println("valueoffset:" + attr.valueOffset());
    //            System.out.println("name:"+attr.name());
    //            System.out.println("value:"+attr.value());
    //        }

    // properly the number of the attributes should be one, but the
    // html parser itself serves the three attributes, where first one
    // is correct, second one is completely
    // out of the source are and a third one which represents
    // the close tag after the quotes.
    assertEquals(2, attrs.size());

    Attribute href = attrs.iterator().next();
    assertNotNull(href);

    assertEquals(3, href.from());
    assertEquals(10, href.to());
    assertEquals(3, href.nameOffset());
    assertEquals(8, href.valueOffset());
    assertEquals("href", href.name().toString());
    assertEquals("\"\"", href.value().toString());
    assertEquals("", href.unquotedValue().toString());
  }
Esempio n. 10
0
  public void testLogicalRangesOfUnclosedOpenTags() throws ParseException {
    HtmlParseResult result =
        parse(
            "<!DOCTYPE html>"
                + "<html>"
                + "<head>"
                + "<title>hello</title>"
                + "</head>"
                + "<body>"
                + "<table>"
                + "</html>");
    Node root = result.root();

    //        NodeUtils.dumpTree(root);

    assertNotNull(root);
    OpenTag htmlOpen = ElementUtils.query(root, "html");
    assertNotNull(htmlOpen);
    CloseTag htmlEnd = htmlOpen.matchingCloseTag();
    assertNotNull(htmlEnd);

    assertNotNull(ElementUtils.query(root, "html/head"));
    assertNotNull(ElementUtils.query(root, "html/head/title"));
    OpenTag body = ElementUtils.query(root, "html/body");
    assertNotNull(body);
    OpenTag table = ElementUtils.query(root, "html/body/table");
    assertNotNull(table);

    // both body and table should be logically closed at the beginning of the html end tag
    assertEquals(htmlEnd.from(), body.semanticEnd());
    assertEquals(htmlEnd.from(), table.semanticEnd());
  }
Esempio n. 11
0
  // Bug 213332 - IllegalStateException: A bug #212445 just happended for source text "
  // scrollbar-arrow-color:"black"; } </STYLE> <TITLE>Cyprus :: Larnaca</TITLE></HEAD> <BOD". Please
  // report a new bug or r
  // http://netbeans.org/bugzilla/show_bug.cgi?id=213332
  public void testIssue213332() throws ParseException {
    ParseTreeBuilder.setLoggerLevel(Level.ALL);

    String code = "<html><head><style type=text/css></style></head></html>";
    //             012345678901234567890123456789012345678901234567890123456789
    //             0         1         2         3         4         5
    Node root = parse(code).root();

    //        ElementUtils.dumpTree(root);

    OpenTag styleOpen = ElementUtils.query(root, "html/head/style");
    assertNotNull(styleOpen);

    CloseTag styleClose = styleOpen.matchingCloseTag();
    assertNotNull(styleClose);

    assertEquals(33, styleClose.from());
    assertEquals(41, styleClose.to());

    assertEquals(12, styleOpen.from());
    assertEquals(33, styleOpen.to());
  }
Esempio n. 12
0
  // Bug 211776 - Self-closing element breaks code folding
  public void testIssue211776() throws ParseException {
    //        ParseTreeBuilder.setLoggerLevel(Level.ALL);

    HtmlParseResult result = parse(getTestFile("testfiles/test6.html"));
    Node root = result.root();
    //        ElementUtils.dumpTree(root);

    OpenTag body = ElementUtils.query(root, "html/body");
    assertNotNull(body);
    assertFalse(body.isEmpty());

    OpenTag link = ElementUtils.query(root, "html/head/link");
    assertNotNull(link);
    assertTrue(link.isEmpty());

    OpenTag div = ElementUtils.query(root, "html/body/div");
    assertNotNull(div);
    assertFalse(div.isEmpty());
  }
Esempio n. 13
0
  //    //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());
  }
Esempio n. 14
0
  public void testSimpleDocument() throws ParseException {
    String code =
        "<!doctype html><html><head><title>x</title></head><body><div onclick=\"alert();\"/></body></html>";
    //             012345678901234567890123456789012345678901234567890123456789012345678 901234567
    // 8901234567890123456789
    //             0         1         2         3         4         5         6          7
    // 8         9

    //        NodeTreeBuilder.DEBUG_STATES = true;
    HtmlParseResult result = parse(code);
    Node root = result.root();
    assertNotNull(root);
    //        NodeUtils.dumpTree(result.root());

    OpenTag html = ElementUtils.query(root, "html");
    assertEquals("html", html.name());
    assertEquals(15, html.from());
    assertEquals(21, html.to());
    assertEquals(15, html.from());
    assertEquals(95, html.semanticEnd());

    OpenTag body = ElementUtils.query(root, "html/body");
    assertEquals("body", body.name());
    assertEquals(50, body.from());
    assertEquals(56, body.to());
    assertEquals(50, body.from());
    assertEquals(88, body.semanticEnd());

    CloseTag bodyEndTag = body.matchingCloseTag();
    assertNotNull(bodyEndTag);
    assertSame(body, bodyEndTag.matchingOpenTag());
    assertSame(bodyEndTag, body.matchingCloseTag());

    OpenTag title = ElementUtils.query(root, "html/head/title");
    assertEquals("title", title.name());
    assertEquals(27, title.from());
    assertEquals(34, title.to());
    assertEquals(27, title.from());
    assertEquals(43, title.semanticEnd());

    CloseTag titleEndTag = title.matchingCloseTag();
    assertNotNull(titleEndTag);
    assertSame(title, titleEndTag.matchingOpenTag());
    assertSame(titleEndTag, title.matchingCloseTag());
  }