Skip to content

Commit 7125139

Browse files
committed
Python: Address review
1 parent 81a5692 commit 7125139

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

python/ql/src/semmle/python/regex.qll

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,14 @@ abstract class RegexString extends Expr {
124124
)
125125
}
126126

127-
/** Escaped characters without any special handling (yet) */
128-
private predicate singleEscape(int i) {
129-
exists(string c |
130-
c = this.getChar(i) and
131-
c != "x" and c != "u" and c != "U" and c != "N"
132-
)
133-
}
134-
135127
/** Named unicode characters, eg \N{degree sign} */
136128
private predicate escapedName(int start, int end) {
129+
this.escapingChar(start) and
137130
this.getChar(start + 1) = "N" and
138131
this.getChar(start + 2) = "{" and
139132
this.getChar(end - 1) = "}" and
140133
end > start and
141-
not exists(int i |
142-
i > start + 2 and
143-
i < end - 1 and
134+
not exists(int i | start + 2 < i and i < end - 1 |
144135
this.getChar(i) = "}"
145136
)
146137
}
@@ -156,16 +147,17 @@ abstract class RegexString extends Expr {
156147
end in [start + 2 .. start + 4] and
157148
exists(this.getText().substring(start + 1, end).toInt())
158149
or
159-
// 16-bit hex value
150+
// 16-bit hex value \uhhhh
160151
this.getChar(start + 1) = "u" and end = start + 6
161152
or
162-
// 32-bit hex value
153+
// 32-bit hex value \Uhhhhhhhh
163154
this.getChar(start + 1) = "U" and end = start + 10
164155
or
165156
escapedName(start, end)
166157
or
167-
// single character not handled above, update when adding a new case
168-
this.singleEscape(start + 1) and end = start + 2
158+
// escape not handled above, update when adding a new case
159+
not this.getChar(start + 1) in ["x", "u", "U", "N"] and
160+
end = start + 2
169161
)
170162
}
171163

0 commit comments

Comments
 (0)