use of cfml.parsing.reporting.ArrayErrorListener in project CFLint by cflint.
the class CFLint method unpackTagExpressions.
private Map<String, CFExpression> unpackTagExpressions(final Element elem) {
// Use LinkedHashMap to preserve the order
final Map<String, CFExpression> expressions = new LinkedHashMap<>();
if (!elem.getName().toLowerCase().startsWith("cf") || elem.getAttributes() == null) {
return expressions;
}
// variable attribute
for (final Attribute attr : elem.getAttributes()) {
if (detectScript(attr)) {
// Try wrapping the expression in single or double quotes for
// parsing.
final List<String> literalChar = attr.getValue().contains("'") ? Arrays.asList("\"", "'") : Arrays.asList("'", "\"");
try {
final List<String> errors = new ArrayList<>();
final ANTLRErrorListener errorReporter = new ArrayErrorListener(errors);
final CFExpression exp = cfmlParser.parseCFMLExpression(literalChar.get(0) + attr.getValue() + literalChar.get(0), errorReporter);
if (errors.isEmpty()) {
expressions.put(attr.getName().toLowerCase(), exp);
continue;
}
} catch (final Exception e) {
}
// Try other quotes before reporting a failure
try {
final CFExpression exp = cfmlParser.parseCFMLExpression(literalChar.get(1) + attr.getValue() + literalChar.get(1), this);
expressions.put(attr.getName().toLowerCase(), exp);
} catch (final Exception e2) {
System.err.println("Error in parsing : " + attr.getValue() + " on tag " + elem.getName());
}
} else if (tagInfo.isExpressionAttribute(elem, attr.getName())) {
try {
final CFExpression exp = cfmlParser.parseCFMLExpression(attr.getValue(), this);
expressions.put(attr.getName().toLowerCase(), exp);
} catch (final Exception e2) {
System.err.println("Error in parsing : " + attr.getValue() + " on tag " + elem.getName());
}
}
}
return expressions;
}
Aggregations