Ejemplo n.º 1
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());
  }
Ejemplo n.º 2
0
 private static OffsetRange getAttributeValueOffsetRange(Attribute attr, HtmlRuleContext context) {
   boolean quoted = attr.isValueQuoted();
   int from = attr.valueOffset() + (quoted ? 1 : 0);
   int to = from + attr.unquotedValue().length();
   return EmbeddingUtil.convertToDocumentOffsets(from, to, context.getSnapshot());
 }