You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tune the suspicious_regex linter to make it less noisy
* Allow unescaped '.' when followed by a quantifier (e.g., '.*', '.+',
'.?','.{') since those are commonly intentional uses of the dot
metacharacter.
* Allow 'https?' patterns without flagging the '?' as suspicious since
that's a common pattern for matching both 'http' and 'https'.
// Treat an unescaped '.' as suspicious only when it's not immediately
60
+
// followed by a quantifier (e.g., '.*', '.+', '.?','.{') since those
61
+
// are commonly intentional uses of the dot metacharacter.
62
+
let next_is_quant = matches!(next,Some('*' | '+' | '?' | '{'));
63
+
if !next_is_quant {
64
+
has_unescaped_dot_literal = true;
65
+
}
59
66
}
67
+
60
68
if c == '?'{
61
-
has_q = true;
69
+
// Ignore the ? if the previous character is a quantifier (e.g., '.*?', '.+?') or otherwise part of a sensible use
70
+
// (? starts regex commands eg (?i) or (?:...), so we only flag it when it looks like a literal question mark that might be intended as a query separator.
71
+
// Optional character classes like [a-z]? are common
// Full URI: unescaped dots and question marks are common mistakes
137
-
if has_dot || has_q {
141
+
// Allow matching on optional 's' in 'https' (e.g., https?://) without flagging as suspicious since that's a common pattern, but flag other unescaped '?' characters that look like they might be intended as query separators.
142
+
if has_dot || (has_q && !pattern.contains("https?")){
138
143
suspicious = true;
139
144
message = r"Regex contains unescaped `.` or `?` characters in a URI; escape them (e.g., `\.` and `\?`) or use a wildcard match where appropriate.".to_string();
0 commit comments