@@ -52,14 +52,10 @@ abstract class RegexString extends StringLiteral {
5252 * This leads to very similar results for ReDoS queries.
5353 */
5454 predicate charSet ( int start , int end ) {
55- exists ( int inner_start , int inner_end |
56- this .charSetStart ( start , inner_start ) and
57- not this .charSetStart ( _, start )
58- |
55+ exists ( int inner_start , int inner_end | this .charSetStart ( start , inner_start ) |
5956 end = inner_end + 1 and
60- inner_end > inner_start and
61- this .charSetEnd ( inner_end ) and
62- not exists ( int mid | this .charSetEnd ( mid ) | mid > inner_start and mid < inner_end )
57+ inner_end =
58+ min ( int end_delimiter | this .charSetEnd ( end_delimiter ) and end_delimiter > inner_start )
6359 )
6460 }
6561
@@ -159,7 +155,7 @@ abstract class RegexString extends StringLiteral {
159155
160156 /**
161157 * Helper predicate for `escapingChar`.
162- * In order to avoid negative recusrion , we return a boolean.
158+ * In order to avoid negative recursion , we return a boolean.
163159 * This way, we can refer to `escaping(pos - 1).booleanNot()`
164160 * rather than to a negated version of `escaping(pos)`.
165161 * Does not take into account escape characters inside quote sequences.
@@ -199,13 +195,13 @@ abstract class RegexString extends StringLiteral {
199195 */
200196 private boolean quoteDelimiter ( int index , int pos ) {
201197 result = this .quoteDelimiter ( pos ) and
202- pos = rank [ index ] ( int p | this .quoteDelimiter ( p ) = [ true , false ] )
198+ pos = rank [ index ] ( int p | exists ( this .quoteDelimiter ( p ) ) )
203199 }
204200
205201 /** Holds if a quoted sequence is found between `start` and `end` */
206202 predicate quote ( int start , int end ) { this .quote ( start , end , _, _) }
207203
208- /** Holds if a quoted sequence is fund between `start` and `end`, with ontent found between `inner_start` and `inner_end`. */
204+ /** Holds if a quoted sequence is found between `start` and `end`, with ontent found between `inner_start` and `inner_end`. */
209205 predicate quote ( int start , int end , int inner_start , int inner_end ) {
210206 exists ( int index |
211207 this .quoteDelimiter ( index , start ) = true and
@@ -216,11 +212,10 @@ abstract class RegexString extends StringLiteral {
216212 ) and
217213 inner_start = start + 2 and
218214 inner_end = end - 2 and
219- inner_end > inner_start and
220- this .quoteDelimiter ( inner_end ) = false and
221- not exists ( int mid |
222- this .quoteDelimiter ( mid ) = false and mid in [ inner_start .. inner_end - 1 ]
223- )
215+ inner_end =
216+ min ( int end_delimiter |
217+ this .quoteDelimiter ( end_delimiter ) = false and end_delimiter > inner_start
218+ )
224219 )
225220 }
226221
@@ -266,9 +261,7 @@ abstract class RegexString extends StringLiteral {
266261 this .escapingChar ( start ) and
267262 this .getChar ( start + 1 ) = [ "N" , "p" , "P" , "x" ] and
268263 this .getChar ( start + 2 ) = "{" and
269- this .getChar ( end - 1 ) = "}" and
270- end > start and
271- not exists ( int i | start + 2 < i and i < end - 1 | this .getChar ( i ) = "}" )
264+ end = min ( int i | start + 2 < i and this .getChar ( i - 1 ) = "}" )
272265 }
273266
274267 /**
@@ -301,7 +294,7 @@ abstract class RegexString extends StringLiteral {
301294 or
302295 this .escapedBraces ( start , end )
303296 or
304- // Boundry matchers \b, \b{g}
297+ // Boundary matchers \b, \b{g}
305298 this .getChar ( start + 1 ) = "b" and
306299 (
307300 if this .getText ( ) .substring ( start + 2 , start + 5 ) = "{g}"
@@ -654,9 +647,7 @@ abstract class RegexString extends StringLiteral {
654647 this .shortQuantifier ( start , end , maybe_empty , may_repeat_forever ) and
655648 not this .getChar ( end ) = [ "?" , "+" ]
656649 or
657- exists ( int short_end |
658- this .shortQuantifier ( start , short_end , maybe_empty , may_repeat_forever )
659- |
650+ exists ( int short_end | this .shortQuantifier ( start , short_end , maybe_empty , may_repeat_forever ) |
660651 if this .getChar ( short_end ) = [ "?" , "+" ] then end = short_end + 1 else end = short_end
661652 )
662653 }
@@ -752,11 +743,11 @@ abstract class RegexString extends StringLiteral {
752743 * a character set or a group.
753744 */
754745 predicate sequence ( int start , int end ) {
755- this .sequenceOrquantified ( start , end ) and
746+ this .sequenceOrQuantified ( start , end ) and
756747 not this .quantifiedItem ( start , end , _, _)
757748 }
758749
759- private predicate sequenceOrquantified ( int start , int end ) {
750+ private predicate sequenceOrQuantified ( int start , int end ) {
760751 this .subsequence ( start , end ) and
761752 not this .itemStart ( end )
762753 }
@@ -787,7 +778,7 @@ abstract class RegexString extends StringLiteral {
787778 }
788779
789780 private predicate subalternation ( int start , int end , int itemStart ) {
790- this .sequenceOrquantified ( start , end ) and
781+ this .sequenceOrQuantified ( start , end ) and
791782 not this .isOptionDivider ( start - 1 ) and
792783 itemStart = start
793784 or
@@ -801,7 +792,7 @@ abstract class RegexString extends StringLiteral {
801792 this .isOptionDivider ( mid ) and
802793 itemStart = mid + 1
803794 |
804- this .sequenceOrquantified ( itemStart , end )
795+ this .sequenceOrQuantified ( itemStart , end )
805796 or
806797 not this .itemStart ( end ) and end = itemStart
807798 )
0 commit comments