From 51058cccfafb6c35014da4eab1c313527ef96756 Mon Sep 17 00:00:00 2001 From: Sergey Date: Tue, 28 Feb 2017 14:11:49 -0800 Subject: [PATCH] Moving Pattern to final static --- .../pmd/lang/vf/rule/security/VfUnescapeElRule.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 8a84e41f08..74299b7bc3 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 @@ -40,6 +40,8 @@ public class VfUnescapeElRule extends AbstractVfRule { private static final String APEX_PAGE_MESSAGES = "apex:pagemessages"; private static final String APEX_SELECT_OPTION = "apex:selectoption"; private static final String FALSE = "false"; + private static final Pattern ON_EVENT = Pattern.compile("^on(\\w)+$"); + private static final Pattern PLACEHOLDERS = Pattern.compile("\\{(\\w|,|\\.|'|:|\\s)*\\}"); @Override public Object visit(ASTElement node, Object data) { @@ -60,7 +62,8 @@ public class VfUnescapeElRule extends AbstractVfRule { for (ASTAttribute attr : attributes) { String name = attr.getName().toLowerCase(); // look for onevents - if (Pattern.compile("^on(\\w)+$").matcher(name).matches()) { + + if (ON_EVENT.matcher(name).matches()) { final List elsInVal = attr.findDescendantsOfType(ASTElExpression.class); for (ASTElExpression el : elsInVal) { if (doesElContainAnyUnescapedIdentifiers(el, @@ -158,7 +161,8 @@ public class VfUnescapeElRule extends AbstractVfRule { final ASTText textValue = attr.getFirstDescendantOfType(ASTText.class); if (textValue != null) { - if (Pattern.compile("\\{(\\w|,|\\.|'|:|\\s)*\\}").matcher(textValue.getImage()).matches()) { + + if (PLACEHOLDERS.matcher(textValue.getImage()).matches()) { hasPlaceholders = true; } }