diff --git a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/VfUnescapeElRule.java b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/VfUnescapeElRule.java index f19ef5f568..6c32076a92 100644 --- a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/VfUnescapeElRule.java +++ b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/security/VfUnescapeElRule.java @@ -72,13 +72,8 @@ public class VfUnescapeElRule extends AbstractVfRule { boolean quoted = false; if (prevText != null) { - if ("'".equals(prevText.jjtGetLastToken()) || "\"".equals(prevText.jjtGetLastToken())) { + if (isUnbalanced(prevText.getImage(), "'") || isUnbalanced(prevText.getImage(), "\"")) { quoted = true; - } else { - if (prevText.getImage() != null - && (prevText.getImage().contains("'") | prevText.getImage().contains("\""))) { - quoted = true; - } } } if (quoted) { @@ -95,6 +90,22 @@ public class VfUnescapeElRule extends AbstractVfRule { } } + private boolean isUnbalanced(String image, String pattern) { + int occurance = 0; + int index = image.lastIndexOf("="); + index = image.indexOf(pattern, index + 1); + while (index >= 0) { + occurance++; + index = image.indexOf(pattern, index + 1); + } + + if ((occurance % 2) != 0) { + return true; + } + + return false; + } + @Override public Object visit(ASTElement node, Object data) { if (doesTagSupportEscaping(node)) {