Merge branch 'pr-368'

This commit is contained in:
Andreas Dangel
2017-05-01 16:51:26 +02:00
7 changed files with 51 additions and 11 deletions

View File

@ -146,7 +146,7 @@ PARSER_END(VfParser)
| <GE: ">=" >
| <LT: "<" >
| <GT: ">" >
| <EXCL: ("!"|"~") >
| <EXCL: ("!"|"~"|"NOT") >
| <PIPE_PIPE: "||" >
| <STRING_LITERAL: <QUOTED_STRING> >
| <DIGITS: (<NUM_CHAR>)+ (<DOT> (<NUM_CHAR>)+)? >
@ -496,14 +496,7 @@ void UnaryExpression() #void :
{}
{
( <PLUS> | <MINUS> ) UnaryExpression()
| NegationExpression()
}
void NegationExpression() #void :
{}
{
( <EXCL> ) UnaryExpression()
| PrimaryExpression()
| PrimaryExpression()
}
void PrimaryExpression() #void :
@ -537,6 +530,7 @@ void PrimaryPrefix() #void :
| Identifier()
| <LPAREN> Expression() <RPAREN>
| <LSQUARE> Expression() (<COMMA> Expression())* <RSQUARE>
| NegationExpression()
}
void PrimarySuffix() #void :
@ -547,6 +541,13 @@ void PrimarySuffix() #void :
| Arguments()
}
void NegationExpression() :
{}
{
( <EXCL> ) Expression()
}
void DotExpression() :
{}
{

View File

@ -0,0 +1,21 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.vf.ast;
public class ASTNegationExpression extends AbstractVFNode {
public ASTNegationExpression(int id) {
super(id);
}
public ASTNegationExpression(VfParser p, int id) {
super(p, id);
}
/** Accept the visitor. **/
public Object jjtAccept(VfParserVisitor visitor, Object data) {
return visitor.visit(this, data);
}
}

View File

@ -85,4 +85,9 @@ public class VfParserVisitorAdapter implements VfParserVisitor {
return visit((VfNode) node, data);
}
@Override
public Object visit(ASTNegationExpression node, Object data) {
return visit((VfNode) node, data);
}
}

View File

@ -28,6 +28,7 @@ import net.sourceforge.pmd.lang.vf.ast.ASTExpression;
import net.sourceforge.pmd.lang.vf.ast.ASTHtmlScript;
import net.sourceforge.pmd.lang.vf.ast.ASTIdentifier;
import net.sourceforge.pmd.lang.vf.ast.ASTLiteral;
import net.sourceforge.pmd.lang.vf.ast.ASTNegationExpression;
import net.sourceforge.pmd.lang.vf.ast.ASTText;
import net.sourceforge.pmd.lang.vf.ast.VfNode;
import net.sourceforge.pmd.lang.vf.ast.VfParserVisitor;
@ -127,4 +128,8 @@ public abstract class AbstractVfRule extends AbstractRule implements VfParserVis
return visit((VfNode) node, data);
}
public Object visit(ASTNegationExpression node, Object data) {
return visit((VfNode) node, data);
}
}

View File

@ -21,6 +21,7 @@ import net.sourceforge.pmd.lang.vf.ast.ASTExpression;
import net.sourceforge.pmd.lang.vf.ast.ASTHtmlScript;
import net.sourceforge.pmd.lang.vf.ast.ASTIdentifier;
import net.sourceforge.pmd.lang.vf.ast.ASTLiteral;
import net.sourceforge.pmd.lang.vf.ast.ASTNegationExpression;
import net.sourceforge.pmd.lang.vf.ast.ASTText;
import net.sourceforge.pmd.lang.vf.ast.AbstractVFNode;
import net.sourceforge.pmd.lang.vf.rule.AbstractVfRule;
@ -245,6 +246,11 @@ public class VfUnescapeElRule extends AbstractVfRule {
private boolean startsWithSafeResource(final ASTElExpression el) {
final ASTExpression expression = el.getFirstChildOfType(ASTExpression.class);
if (expression != null) {
final ASTNegationExpression negation = expression.getFirstChildOfType(ASTNegationExpression.class);
if (negation != null) {
return true;
}
final ASTIdentifier id = expression.getFirstChildOfType(ASTIdentifier.class);
if (id != null) {
List<ASTArguments> args = expression.findChildrenOfType(ASTArguments.class);
@ -254,8 +260,7 @@ public class VfUnescapeElRule extends AbstractVfRule {
case "casesafeid":
case "begins":
case "contains":
case "len":
case "not":
case "len":
case "getrecordids":
case "linkto":
case "sqrt":

View File

@ -567,6 +567,7 @@ NOT method evaluates to safe boolean
<apex:page>
<script>
if({!NOT(yes)}) { maskFormEls(); }
if({!NOT foo(yes)}) { maskFormEls(); }
</script>
</apex:page>
]]></code>

View File

@ -20,3 +20,5 @@ This is a minor release.
### API Changes
### External Contributions
* [#368](https://github.com/pmd/pmd/pull/368): \[vf] Adding proper AST support for negation expressions