Skip to content

Commit

Permalink
[Misc] Fix the DOCTYPE validation test: use the real API and provide …
Browse files Browse the repository at this point in the history
…more accurate errors
  • Loading branch information
tmortagne committed Dec 4, 2024
1 parent 0321b79 commit 4b29c1d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -29,6 +30,7 @@
import org.apache.commons.lang3.StringUtils;
import org.jsoup.nodes.DocumentType;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.select.Elements;
import org.w3c.dom.Document;
import org.xwiki.validator.ValidationError.Type;
Expand Down Expand Up @@ -60,6 +62,8 @@ public class HTML5DutchWebGuidelinesValidator extends AbstractHTML5Validator
private static final String SUBMIT_BUTTONS = StringUtils.join(Arrays.asList("button[type='submit']",
"button:not([type])", "input[type='submit']", "input[type='image'][alt]:not([alt=''])"), ", ");

private static final String DOCTYPE_ATT_NAME = "name";

/**
* Message resources.
*/
Expand Down Expand Up @@ -606,12 +610,25 @@ public void validateRpd5s1()
*/
public void validateRpd6s1()
{
boolean validDocumentType = this.html5Document.childNodes().stream()
.filter(node -> node instanceof DocumentType)
.anyMatch(documentType -> "html".equalsIgnoreCase(documentType.attr("name")) && StringUtils
.isAllEmpty(documentType.attr("publicId"), documentType.attr("systemId")));
// Get the DOCTYPE
Optional<Node> docttype =
this.html5Document.childNodes().stream().filter(DocumentType.class::isInstance).findFirst();

// Make sure there is a DOCTYPE
if (docttype.isPresent()) {
DocumentType documentType = (DocumentType) docttype.get();

// Make sure the DOCTYPE name is "html"
assertTrue(Type.ERROR, "rpd6s1.doctypenothtml", "html".equals(documentType.name()));

assertTrue(Type.ERROR, "rpd6s1.doctype", validDocumentType);
// Make sure the DOCTYPE systemId is not set
assertTrue(Type.ERROR, "rpd6s1.doctypesystemid", StringUtils.isEmpty(documentType.systemId()));

// Make sure the DOCTYPE publicId is not set
assertTrue(Type.ERROR, "rpd6s1.doctypepublicid", StringUtils.isEmpty(documentType.publicId()));
} else {
addError(Type.ERROR, -1, -1, "rpd6s1.nodoctype");
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ rpd3s9.sub=The use of <sub> is not recommended.
rpd3s9.sup=The use of <sup> is not recommended.
rpd3s11.quotation=It is recommended to be careful with <q>, because support for the element is not by default available in all browsers. Check in the latest versions of Internet Explorer whether the lack of support for the <q> element in this browser is adequately compensated.
rpd3s13.lists=It seems that lists appear on this page (single lines under each other starting with a * or - or [0-9].), and is not contained within <ol> or <ul> tags.
rpd6s1.doctype=The document seems to contain an invalid DOCTYPE
rpd6s1.nodoctype=The document does not contain any DOCTYPE
rpd6s1.doctypenothtml=The document DOCTYPE name is not html
rpd6s1.doctypesystemid=The document DOCTYPE has a system id
rpd6s1.doctypepublicid=The document DOCTYPE has a public id
rpd7s1.img=At least one <img> element has been found without a alt attribute.
rpd7s1.area=At least one <code>area</code> element has been found without a alt attribute.
rpd7s1.input=At least one <input type="image"> element has been found without a alt attribute.
Expand Down

0 comments on commit 4b29c1d

Please sign in to comment.