[apex] AvoidNonRestrictiveQueries: Fix regex for detecting LIMIT clause
Fixes #5270
This commit is contained in:
parent
00bf6fe2f7
commit
c595fea83f
@ -30,6 +30,8 @@ after JUnit / JUnit 4, even when they applied to JUnit 5 and / or TestNG.
|
||||
The old rule names still work but are deprecated.
|
||||
|
||||
### 🐛 Fixed Issues
|
||||
* apex-performance
|
||||
* [#5270](https://github.com/pmd/pmd/issues/5270): \[apex] AvoidNonRestrictiveQueries when LIMIT is followed by bind expression
|
||||
* java
|
||||
* [#4532](https://github.com/pmd/pmd/issues/4532): \[java] Rule misnomer for JUnit* rules
|
||||
* java-errorprone
|
||||
|
@ -24,7 +24,7 @@ import net.sourceforge.pmd.lang.rule.RuleTargetSelector;
|
||||
import net.sourceforge.pmd.reporting.RuleContext;
|
||||
|
||||
public class AvoidNonRestrictiveQueriesRule extends AbstractApexRule {
|
||||
private static final Pattern RESTRICTIVE_PATTERN = Pattern.compile("(where\\s+)|(limit\\s+)", Pattern.CASE_INSENSITIVE);
|
||||
private static final Pattern RESTRICTIVE_PATTERN = Pattern.compile("\\b(where|limit)\\b", Pattern.CASE_INSENSITIVE);
|
||||
private static final Pattern SELECT_OR_FIND_PATTERN = Pattern.compile("(select\\s+|find\\s+)", Pattern.CASE_INSENSITIVE);
|
||||
private static final Pattern SUB_QUERY_PATTERN = Pattern.compile("(?i)\\(\\s*select\\s+[^)]+\\)");
|
||||
|
||||
|
@ -260,6 +260,36 @@ public class Something {
|
||||
.isEmpty();
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>[apex] AvoidNonRestrictiveQueries when LIMIT is followed by bind expression #5270</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public with sharing class DemoController {
|
||||
public static final Integer LIMIT_ACCOUNTS = 2;
|
||||
@AuraEnabled
|
||||
public static List<Account> getTwoAccounts() {
|
||||
List<Account> result = [
|
||||
SELECT Id, Name FROM Account WITH SECURITY_ENFORCED
|
||||
LIMIT:LIMIT_ACCOUNTS // note: no spaces... - false positive here
|
||||
];
|
||||
List<Account> result2 = [
|
||||
SELECT Id, Name FROM Account WITH SECURITY_ENFORCED
|
||||
LIMIT :LIMIT_ACCOUNTS
|
||||
];
|
||||
List<Account> result3 = [
|
||||
SELECT Id, Name FROM Account WITH SECURITY_ENFORCED
|
||||
LIMIT : LIMIT_ACCOUNTS
|
||||
];
|
||||
|
||||
// sosl:
|
||||
List<List<SObject>> searchList = [FIND 'map*' IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, Lead LIMIT:LIMIT_ACCOUNTS];
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
||||
|
Loading…
x
Reference in New Issue
Block a user