TemplateProcessor.verifySelector(...) uses jsoup library incorrectly when matching the "data-field" attribute value:
private void verifySelector(String selector, Element element, TemplateSelector templateSelector,
org.jsoup.nodes.Element root) {
// make sure to use the same logic for finding matching elements as in TemplateUtils!
Elements elements = root.getElementsByAttributeValue("data-field", selector);
Which calls the jsoup library:
/**
* Find elements that have an attribute with the specific value. Case insensitive.
...
*/
public Elements getElementsByAttributeValue(String key, String value) {
This is case insensitive for attribute name (good) and value (BAD!)
Changing ``verifySelector(...) as follows fixes the issue:
//Elements elements = root.getElementsByAttributeValue("data-element", selector);
Elements elements = root.getElementsByAttribute("data-element");
long matchCount = elements.stream().filter(elem -> elem.attributes().getIgnoreCase("data-element").equals(selector)).count();
if (matchCount == 0) {
abortWithError(element,
"Cannot find a matching element in %s using \"[data-element=%s]\" as selector",
templateSelector, selector);
} else if (matchCount > 1) {
warning(element,
"Found %d matching elements in %s using \"[data-element=%s]\" as selector. Only the first will be used.",
elements.size(), templateSelector, selector);
}
TemplateProcessor.verifySelector(...)
uses jsoup library incorrectly when matching the "data-field" attribute value:Which calls the jsoup library:
This is case insensitive for attribute name (good) and value (BAD!)
Changing ``verifySelector(...) as follows fixes the issue: