Add PHP to S6323 (#650)
Co-authored-by: Nils Werner <64034005+nils-werner-sonarsource@users.noreply.github.com>
This commit is contained in:
parent
71cb635542
commit
ddb9c3332b
1
rules/S6323/description.adoc
Normal file
1
rules/S6323/description.adoc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Alternation is used to match a single regular expression out of several possible regular expressions. If one of the alternatives is empty it would match any input, which is most probably a mistake.
|
@ -1,20 +1,2 @@
|
|||||||
{
|
{
|
||||||
"title": "Alternation in regular expressions should not contain empty alternatives",
|
|
||||||
"type": "BUG",
|
|
||||||
"status": "ready",
|
|
||||||
"remediation": {
|
|
||||||
"func": "Constant\/Issue",
|
|
||||||
"constantCost": "5min"
|
|
||||||
},
|
|
||||||
"tags": [
|
|
||||||
"regex"
|
|
||||||
],
|
|
||||||
"defaultSeverity": "Major",
|
|
||||||
"ruleSpecification": "RSPEC-6323",
|
|
||||||
"sqKey": "S6323",
|
|
||||||
"scope": "Main",
|
|
||||||
"defaultQualityProfiles": [
|
|
||||||
"Sonar way"
|
|
||||||
],
|
|
||||||
"quickfix": "unknown"
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
Alternation is used to match a single regular expression out of several possible regular expressions. If one of the alternatives is empty it would match any input, which is most probably a mistake.
|
include::../description.adoc[]
|
||||||
|
|
||||||
== Noncompliant Code Example
|
== Noncompliant Code Example
|
||||||
----
|
----
|
||||||
|
@ -1,2 +1,21 @@
|
|||||||
{
|
{
|
||||||
}
|
"title": "Alternation in regular expressions should not contain empty alternatives",
|
||||||
|
"type": "BUG",
|
||||||
|
"status": "ready",
|
||||||
|
"remediation": {
|
||||||
|
"func": "Constant\/Issue",
|
||||||
|
"constantCost": "5min"
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"regex"
|
||||||
|
],
|
||||||
|
"defaultSeverity": "Major",
|
||||||
|
"ruleSpecification": "RSPEC-6323",
|
||||||
|
"sqKey": "S6323",
|
||||||
|
"scope": "Main",
|
||||||
|
"defaultQualityProfiles": [
|
||||||
|
"Sonar way"
|
||||||
|
],
|
||||||
|
"quickfix": "unknown"
|
||||||
|
}
|
||||||
|
|
2
rules/S6323/php/metadata.json
Normal file
2
rules/S6323/php/metadata.json
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
{
|
||||||
|
}
|
38
rules/S6323/php/rule.adoc
Normal file
38
rules/S6323/php/rule.adoc
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
include::../description.adoc[]
|
||||||
|
|
||||||
|
== Noncompliant Code Example
|
||||||
|
----
|
||||||
|
preg_match("/Jack|Peter|/", "John"); // Noncompliant - returns 1
|
||||||
|
preg_match("/Jack||Peter/", "John"); // Noncompliant - returns 1
|
||||||
|
----
|
||||||
|
== Compliant Solution
|
||||||
|
----
|
||||||
|
preg_match("/Jack|Peter/", "John"); // returns 0
|
||||||
|
----
|
||||||
|
|
||||||
|
== Exceptions
|
||||||
|
|
||||||
|
One could use an empty alternation to make a regular expression group optional. Rule will not report on such cases.
|
||||||
|
|
||||||
|
----
|
||||||
|
preg_match("/mandatory(-optional|)/", "mandatory"); // returns 1
|
||||||
|
preg_match("/mandatory(-optional|)/", "mandatory-optional"); // returns 1
|
||||||
|
----
|
||||||
|
|
||||||
|
ifdef::env-github,rspecator-view[]
|
||||||
|
|
||||||
|
'''
|
||||||
|
== Implementation Specification
|
||||||
|
(visible only on this page)
|
||||||
|
|
||||||
|
== Message
|
||||||
|
|
||||||
|
Remove this empty alternative.
|
||||||
|
|
||||||
|
== Highlighting
|
||||||
|
|
||||||
|
The | should be highlighted.
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
endif::env-github,rspecator-view[]
|
Loading…
x
Reference in New Issue
Block a user