avoid compiling patterns times to times
This commit is contained in:
@ -11,14 +11,15 @@ import net.sourceforge.pmd.lang.vm.ast.ASTText;
|
||||
import net.sourceforge.pmd.lang.vm.rule.AbstractVmRule;
|
||||
|
||||
public class NoInlineJavaScriptRule extends AbstractVmRule {
|
||||
private static final Pattern SCRIPT_PATTERN = Pattern.compile("<script\\s[^>]*>", Pattern.CASE_INSENSITIVE);
|
||||
private static final Pattern SRC_PATTERN = Pattern.compile("\\ssrc\\s*=", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
@Override
|
||||
public Object visit(final ASTText node, final Object data) {
|
||||
final Pattern scriptPattern = Pattern.compile("<script\\s[^>]*>", Pattern.CASE_INSENSITIVE);
|
||||
final Pattern srcPattern = Pattern.compile("\\ssrc\\s*=", Pattern.CASE_INSENSITIVE);
|
||||
final Matcher matcher = scriptPattern.matcher(node.literal());
|
||||
final Matcher matcher = SCRIPT_PATTERN.matcher(node.literal());
|
||||
while (matcher.find()) {
|
||||
final String currentMatch = matcher.group();
|
||||
if (!srcPattern.matcher(currentMatch).find()) {
|
||||
if (!SRC_PATTERN.matcher(currentMatch).find()) {
|
||||
addViolation(data, node);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user