@@ -20,6 +20,12 @@ string invertCase(string s) {
20
20
if s .regexpMatch ( ".*[a-z].*" ) then result = s .toUpperCase ( ) else result = s .toLowerCase ( )
21
21
}
22
22
23
+ RegExpCharacterClass getEnclosingClass ( RegExpTerm term ) {
24
+ term = result .getAChild ( )
25
+ or
26
+ term = result .getAChild ( ) .( RegExpRange ) .getAChild ( )
27
+ }
28
+
23
29
/**
24
30
* Holds if `term` distinguishes between upper and lower case letters, assuming the `i` flag is not present.
25
31
*/
@@ -28,7 +34,7 @@ predicate isCaseSensitiveRegExp(RegExpTerm term) {
28
34
exists ( RegExpConstant const |
29
35
const = term .getAChild * ( ) and
30
36
const .getValue ( ) .regexpMatch ( ".*[a-zA-Z].*" ) and
31
- not const . getParent ( ) . ( RegExpCharacterClass ) .getAChild ( ) .( RegExpConstant ) .getValue ( ) =
37
+ not getEnclosingClass ( const ) .getAChild ( ) .( RegExpConstant ) .getValue ( ) =
32
38
invertCase ( const .getValue ( ) ) and
33
39
not const .getParent * ( ) instanceof RegExpNegativeLookahead and
34
40
not const .getParent * ( ) instanceof RegExpNegativeLookbehind
@@ -59,8 +65,11 @@ string getExampleString(RegExpTerm term) {
59
65
}
60
66
61
67
string getCaseSensitiveBypassExample ( RegExpTerm term ) {
62
- result = invertCase ( getExampleString ( term ) ) and
63
- result != ""
68
+ exists ( string example |
69
+ example = getExampleString ( term ) and
70
+ result = invertCase ( example ) and
71
+ result != example // getting an example string is approximate; ensure we got a proper case-change example
72
+ )
64
73
}
65
74
66
75
/**
@@ -83,7 +92,7 @@ predicate isCaseSensitiveMiddleware(
83
92
isCaseSensitiveRegExp ( regexp .getRoot ( ) ) and
84
93
exists ( string flags |
85
94
flags = regexp .getFlags ( ) and
86
- not flags . matches ( "%i%" )
95
+ not RegExp :: isIgnoreCase ( flags )
87
96
)
88
97
)
89
98
}
0 commit comments