An unbounded repetition in a regular expression repeats a part that can match nothing
What it finds
(a*)* and (x?)+ repeat a part that can match the empty string. The repetition adds nothing that its body does not already match, and makes the matcher try the empty match again and again; it usually means a * or ? slipped into the body.
Reported is an unbounded repetition whose body can match the empty string but contains something that matches characters.
From the rule's source, regex_empty_repeat.rs.
import java.util.regex.Pattern; class Empty { Pattern a = Pattern.compile("(a*)*");tx0 reports: repeats a part that can match nothing Pattern b = Pattern.compile("(?:x?)+y");tx0 reports: can match nothing Pattern c = Pattern.compile("(ab?)*");} 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:
[rules]
"tx0/java:regex-empty-repeat" = "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-empty-repeat] reason="..."tx0 explain tx0/java:regex-empty-repeat shows the same in the terminal. Found a false positive? Report it.