예제 #1
0
  // 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());
  }
예제 #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());
 }