use of net.htmlparser.jericho.Attribute 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) {
if (!quiet) {
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) {
if (!quiet) {
System.err.println("Error in parsing : " + attr.getValue() + " on tag " + elem.getName());
}
}
}
}
// Parse the body
if (elem.getName().toLowerCase().equals("cfoutput")) {
final String content = elem.getContent().getTextExtractor().toString();
if (content != null && content.length() > 0 && content.contains("#")) {
final List<String> errors = new ArrayList<>();
final ANTLRErrorListener errorReporter = new ArrayErrorListener(errors);
try {
final CFExpression exp = cfmlParser.parseCFMLExpression(content, errorReporter);
if (errors.isEmpty()) {
expressions.put("body", exp);
}
} catch (final Exception e) {
}
}
}
return expressions;
}
use of net.htmlparser.jericho.Attribute in project CFLint by cflint.
the class VariableNameChecker method checkCFName.
// private final List<String> exclusions = new ArrayList<>();
private void checkCFName(final Element element, final Context context, final BugList bugs, final int begLine, int offset, final String name) {
if (element.getAttributeValue(name) != null) {
final Attribute attribute = element.getAttributes().get(name);
String varName;
if (attribute != null) {
varName = CFScopes.descope(attribute.getValue());
offset = attribute.getValueSegment().getBegin();
} else {
varName = "";
}
if (varName.length() > 0 && !varName.contains("#")) {
checkNameForBugs(context, varName, varName, context.getFilename(), context.getFunctionName(), begLine, offset, bugs, null);
}
}
}
use of net.htmlparser.jericho.Attribute in project vue-gwt by Axellience.
the class TemplateParser method processElement.
/**
* Recursive method that will process the whole template DOM tree.
* @param element Current element being processed
*/
private void processElement(Element element) {
context.setCurrentSegment(element);
currentProp = null;
currentAttribute = null;
Attributes attributes = element.getAttributes();
Attribute vForAttribute = attributes != null ? attributes.get("v-for") : null;
if (vForAttribute != null) {
// Add a context layer for our v-for
context.addContextLayer();
// Process the v-for expression, and update our attribute
String processedVForValue = processVForValue(vForAttribute.getValue());
outputDocument.replace(vForAttribute.getValueSegment(), processedVForValue);
}
// Process the element
if (attributes != null)
processElementAttributes(element);
// Process text segments
StreamSupport.stream(((Iterable<Segment>) element::getNodeIterator).spliterator(), false).filter(segment -> !(segment instanceof Tag) && !(segment instanceof CharacterReference)).filter(segment -> {
for (Element child : element.getChildElements()) if (child.encloses(segment))
return false;
return true;
}).forEach(this::processTextNode);
// Recurse downwards
element.getChildElements().forEach(this::processElement);
// After downward recursion, pop the context layer
if (vForAttribute != null)
context.popContextLayer();
}
use of net.htmlparser.jericho.Attribute in project zaproxy by zaproxy.
the class SpiderHtmlFormParser method parseResource.
@Override
public boolean parseResource(HttpMessage message, Source source, int depth) {
getLogger().debug("Parsing an HTML message for forms...");
// If form processing is disabled, don't parse anything
if (!param.isProcessForm()) {
return false;
}
// Prepare the source, if not provided
if (source == null) {
source = new Source(message.getResponseBody().toString());
}
// Get the context (base url)
String baseURL = message.getRequestHeader().getURI().toString();
uri = message.getRequestHeader().getURI();
// Try to see if there's any BASE tag that could change the base URL
Element base = source.getFirstElement(HTMLElementName.BASE);
if (base != null) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Base tag was found in HTML: " + base.getDebugInfo());
}
String href = base.getAttributeValue("href");
if (href != null && !href.isEmpty()) {
baseURL = URLCanonicalizer.getCanonicalURL(href, baseURL);
}
}
// Go through the forms
List<Element> forms = source.getAllElements(HTMLElementName.FORM);
for (Element form : forms) {
// Clear the attributes for each form and store their key and values
envAttributes.clear();
for (Attribute att : form.getAttributes()) {
envAttributes.put(att.getKey(), att.getValue());
}
// Get method and action
String method = form.getAttributeValue("method");
String action = form.getAttributeValue("action");
getLogger().debug("Found new form with method: '" + method + "' and action: " + action);
// If no action, skip the form
if (action == null) {
getLogger().debug("No form 'action' defined. Using base URL: " + baseURL);
action = baseURL;
}
// If POSTing forms is not enabled, skip processing of forms with POST method
if (!param.isPostForm() && method != null && method.trim().equalsIgnoreCase(METHOD_POST)) {
getLogger().debug("Skipping form with POST method because of user settings.");
continue;
}
// Clear the fragment, if any, as it does not have any relevance for the server
if (action.contains("#")) {
int fs = action.lastIndexOf("#");
action = action.substring(0, fs);
}
url = URLCanonicalizer.getCanonicalURL(action, baseURL);
FormData formData = prepareFormDataSet(source, form);
// Process the case of a POST method
if (method != null && method.trim().equalsIgnoreCase(METHOD_POST)) {
// Build the absolute canonical URL
String fullURL = URLCanonicalizer.getCanonicalURL(action, baseURL);
if (fullURL == null) {
return false;
}
getLogger().debug("Canonical URL constructed using '" + action + "': " + fullURL);
for (String submitData : formData) {
notifyPostResourceFound(message, depth, fullURL, submitData);
}
} else // Process anything else as a GET method
{
// Process the final URL
if (action.contains("?")) {
if (action.endsWith("?")) {
processGetForm(message, depth, action, baseURL, formData);
} else {
processGetForm(message, depth, action + "&", baseURL, formData);
}
} else {
processGetForm(message, depth, action + "?", baseURL, formData);
}
}
}
return false;
}
Aggregations