use of org.sonar.plugins.html.node.TagNode in project sonar-web by SonarSource.
the class PageLexerTest method testAttributeWithoutQuotes.
@Test
public void testAttributeWithoutQuotes() {
final StringReader reader = new StringReader("<img src=http://foo/sfds?sjg a=1\tb=2\r\nc=3 />");
final PageLexer lexer = new PageLexer();
final List<Node> nodeList = lexer.parse(reader);
assertThat(nodeList).hasSize(1);
assertThat(nodeList.get(0)).isInstanceOf(TagNode.class);
final TagNode node = (TagNode) nodeList.get(0);
assertThat(node.getAttributes()).hasSize(4);
final Attribute attribute = node.getAttributes().get(0);
assertThat(attribute.getName()).isEqualTo("src");
assertThat(attribute.getValue()).isEqualTo("http://foo/sfds?sjg");
final Attribute attributeA = node.getAttributes().get(1);
assertThat(attributeA.getName()).isEqualTo("a");
assertThat(attributeA.getValue()).isEqualTo("1");
final Attribute attributeB = node.getAttributes().get(2);
assertThat(attributeB.getName()).isEqualTo("b");
assertThat(attributeB.getValue()).isEqualTo("2");
final Attribute attributeC = node.getAttributes().get(3);
assertThat(attributeC.getName()).isEqualTo("c");
assertThat(attributeC.getValue()).isEqualTo("3");
}
use of org.sonar.plugins.html.node.TagNode in project sonar-web by SonarSource.
the class PageLexerTest method assertNodes.
private static void assertNodes(TagNode actual, TestNode expected) {
assertThat(actual.getNodeName()).isEqualTo(expected.nodeName);
assertThat(actual.getChildren()).as(actual.getNodeName() + " children:").hasSize(expected.children.length);
int i = 0;
for (TagNode child : actual.getChildren()) {
assertNodes(child, expected.children[i]);
i++;
}
}
use of org.sonar.plugins.html.node.TagNode in project sonar-web by SonarSource.
the class PageLexerTest method should_recover_on_invalid_attribute.
@Test
public void should_recover_on_invalid_attribute() {
PageLexer lexer = new PageLexer();
List<Node> nodes = lexer.parse(new StringReader("<foo = bar=42>"));
assertThat(nodes).hasSize(1);
assertThat(((TagNode) nodes.get(0)).getAttribute("bar")).isEqualTo("42");
}
use of org.sonar.plugins.html.node.TagNode in project sonar-web by SonarSource.
the class PageLexerTest method attribute_value_starting_with_quote.
@Test
public void attribute_value_starting_with_quote() {
StringReader reader = new StringReader("<img src=\"'a'\"/>");
List<Node> nodeList = new PageLexer().parse(reader);
assertThat(nodeList).hasSize(1);
assertThat(nodeList.get(0)).isInstanceOf(TagNode.class);
TagNode node = (TagNode) nodeList.get(0);
Attribute attribute = node.getAttributes().get(0);
assertThat(attribute.getName()).isEqualTo("src");
assertThat(attribute.getValue()).isEqualTo("'a'");
}
use of org.sonar.plugins.html.node.TagNode in project sonar-web by SonarSource.
the class TableHeaderReferenceCheck method raiseViolationOnInvalidReference.
private void raiseViolationOnInvalidReference(Table table) {
Map<TagNode, List<String>> referenceableHeaders = table.findReferenceableHeadersPerCellNode();
Map<TagNode, List<String>> raisedFor = new HashMap<>();
table.forEachCell((cell, row, column) -> {
TagNode node = cell.node();
List<String> actual = cell.headers();
List<String> expected = referenceableHeaders.getOrDefault(node, Collections.emptyList());
for (String header : actual) {
if (!expected.contains(header) && !raisedFor.getOrDefault(node, Collections.emptyList()).contains(header)) {
if (isExistingHeader(table, header)) {
createViolation(node, format("id \"%s\" in \"headers\" reference the header of another column/row.", header));
} else {
createViolation(node, format("id \"%s\" in \"headers\" does not reference any <th> header.", header));
}
raisedFor.merge(node, Arrays.asList(header), (acc, val) -> {
acc.addAll(val);
return acc;
});
break;
}
}
});
}
Aggregations