A regular expression ignores case for letters beyond ASCII without the flag that makes it do so

tx0/java:regex-unicode-case-missingrecommendedwarningbug

What it finds

Pattern.compile("straße", Pattern.CASE_INSENSITIVE) still tells ß from SS and é from É: by itself the flag ignores case for ASCII letters only, as the documentation of Pattern.CASE_INSENSITIVE says. UNICODE_CASE, or (?iu) inside the pattern, extends it to all letters.

Reported is a pattern that ignores case, by flag or (?i), contains a letter beyond ASCII and does not ask for UNICODE_CASE, (?u), UNICODE_CHARACTER_CLASS or (?U).

From the rule's source, regex_unicode_case_missing.rs.

Example from the rule's tests
import java.util.regex.Pattern; class Case {  Pattern a = Pattern.compile("straße", Pattern.CASE_INSENSITIVE);tx0 reports: only for ASCII letters  Pattern b = Pattern.compile("(?i)café");tx0 reports: only for ASCII letters  Pattern c = Pattern.compile("straße", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);  Pattern d = Pattern.compile("street", Pattern.CASE_INSENSITIVE);}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/java:regex-unicode-case-missing" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/java:regex-unicode-case-missing] reason="..."

tx0 explain tx0/java:regex-unicode-case-missing shows the same in the terminal. Found a false positive? Report it.