diff --git a/rules/S5866/highlighting.adoc b/rules/S5866/highlighting.adoc new file mode 100644 index 00000000000..f94093c540b --- /dev/null +++ b/rules/S5866/highlighting.adoc @@ -0,0 +1,4 @@ +=== Highlighting + +The use of `Pattern.CASE_INSENTIVE` or the `i` in `(?i)` or `(?i:...)` + diff --git a/rules/S5866/java/highlighting.adoc b/rules/S5866/java/highlighting.adoc deleted file mode 100644 index a4c34b9e2c1..00000000000 --- a/rules/S5866/java/highlighting.adoc +++ /dev/null @@ -1,4 +0,0 @@ -=== Highlighting - -The use of ``++Pattern.CASE_INSENTIVE++`` or the ``++i++`` in ``++(?i)++`` or ``++(?i:...)++`` - diff --git a/rules/S5866/java/metadata.json b/rules/S5866/java/metadata.json index 5a2eb9760e4..2c63c085104 100644 --- a/rules/S5866/java/metadata.json +++ b/rules/S5866/java/metadata.json @@ -1,27 +1,2 @@ { - "title": "Case insensitive Unicode regular expressions should enable the “UNICODE_CASE” flag", - "type": "BUG", - "status": "ready", - "remediation": { - "func": "Constant\/Issue", - "constantCost": "3min" - }, - "tags": [ - "regex" - ], - "extra": { - "replacementRules": [ - - ], - "legacyKeys": [ - - ] - }, - "defaultSeverity": "Major", - "ruleSpecification": "RSPEC-5866", - "sqKey": "S5866", - "scope": "All", - "defaultQualityProfiles": [ - "Sonar way" - ] } diff --git a/rules/S5866/java/rule.adoc b/rules/S5866/java/rule.adoc index cc56eb02765..65438505429 100644 --- a/rules/S5866/java/rule.adoc +++ b/rules/S5866/java/rule.adoc @@ -33,8 +33,8 @@ ifdef::env-github,rspecator-view[] == Implementation Specification (visible only on this page) -include::message.adoc[] +include::../message.adoc[] -include::highlighting.adoc[] +include::../highlighting.adoc[] endif::env-github,rspecator-view[] diff --git a/rules/S5866/kotlin/metadata.json b/rules/S5866/kotlin/metadata.json new file mode 100644 index 00000000000..2c63c085104 --- /dev/null +++ b/rules/S5866/kotlin/metadata.json @@ -0,0 +1,2 @@ +{ +} diff --git a/rules/S5866/kotlin/rule.adoc b/rules/S5866/kotlin/rule.adoc new file mode 100644 index 00000000000..ea0af04473f --- /dev/null +++ b/rules/S5866/kotlin/rule.adoc @@ -0,0 +1,40 @@ +Enabling case-insensitive matching using `(?i)` within a regex will only apply to characters in the ASCII range. To include characters outside of this range, use the `RegexOption.IGNORE_CASE` flag. Alternatively, you can use `(?iu)` or `(?iU)` within the regex instead. + +If not done, regular expressions involving non-ASCII letters will still handle those letters as being case sensitive. + + +== Noncompliant Code Example + +---- +Regex("(?i)söme pättern") +Regex("(?i:söme) pättern") + +"(?i)söme pättern".toRegex() +"(?i:söme) pättern".toRegex() +---- + + +== Compliant Solution + +---- +Regex("söme pättern", RegexOption.IGNORE_CASE) +Regex("(?iu)söme pättern") +Regex("(?iu:söme) pättern") + +"söme pättern".toRegex(RegexOption.IGNORE_CASE) +"(?iu)söme pättern".toRegex() +"(?iu:söme) pättern".toRegex() +---- + + +ifdef::env-github,rspecator-view[] + +''' +== Implementation Specification +(visible only on this page) + +include::../message.adoc[] + +include::../highlighting.adoc[] + +endif::env-github,rspecator-view[] diff --git a/rules/S5866/java/message.adoc b/rules/S5866/message.adoc similarity index 100% rename from rules/S5866/java/message.adoc rename to rules/S5866/message.adoc diff --git a/rules/S5866/metadata.json b/rules/S5866/metadata.json index 2c63c085104..5a2eb9760e4 100644 --- a/rules/S5866/metadata.json +++ b/rules/S5866/metadata.json @@ -1,2 +1,27 @@ { + "title": "Case insensitive Unicode regular expressions should enable the “UNICODE_CASE” flag", + "type": "BUG", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "3min" + }, + "tags": [ + "regex" + ], + "extra": { + "replacementRules": [ + + ], + "legacyKeys": [ + + ] + }, + "defaultSeverity": "Major", + "ruleSpecification": "RSPEC-5866", + "sqKey": "S5866", + "scope": "All", + "defaultQualityProfiles": [ + "Sonar way" + ] }