@@ -124,16 +124,40 @@ abstract class RegexString extends Expr {
124
124
)
125
125
}
126
126
127
+ /** Named unicode characters, eg \N{degree sign} */
128
+ private predicate escapedName ( int start , int end ) {
129
+ this .escapingChar ( start ) and
130
+ this .getChar ( start + 1 ) = "N" and
131
+ this .getChar ( start + 2 ) = "{" and
132
+ this .getChar ( end - 1 ) = "}" and
133
+ end > start and
134
+ not exists ( int i | start + 2 < i and i < end - 1 |
135
+ this .getChar ( i ) = "}"
136
+ )
137
+ }
138
+
127
139
private predicate escapedCharacter ( int start , int end ) {
128
140
this .escapingChar ( start ) and
129
141
not exists ( this .getText ( ) .substring ( start + 1 , end + 1 ) .toInt ( ) ) and
130
142
(
143
+ // hex value \xhh
131
144
this .getChar ( start + 1 ) = "x" and end = start + 4
132
145
or
146
+ // octal value \ooo
133
147
end in [ start + 2 .. start + 4 ] and
134
148
exists ( this .getText ( ) .substring ( start + 1 , end ) .toInt ( ) )
135
149
or
136
- this .getChar ( start + 1 ) != "x" and end = start + 2
150
+ // 16-bit hex value \uhhhh
151
+ this .getChar ( start + 1 ) = "u" and end = start + 6
152
+ or
153
+ // 32-bit hex value \Uhhhhhhhh
154
+ this .getChar ( start + 1 ) = "U" and end = start + 10
155
+ or
156
+ escapedName ( start , end )
157
+ or
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
137
161
)
138
162
}
139
163
0 commit comments