@@ -348,6 +348,7 @@ seems unlikely.)
348348Arguments:
349349 offset index into the offset vector
350350 caseless TRUE if caseless
351+ caseopts bitmask of REFI_FLAG_XYZ values
351352 F the current backtracking frame pointer
352353 mb points to match block
353354 lengthptr pointer for returning the length matched
@@ -358,8 +359,8 @@ Returns: = 0 sucessful match; number of code units matched is set
358359*/
359360
360361static int
361- match_ref (PCRE2_SIZE offset , BOOL caseless , heapframe * F , match_block * mb ,
362- PCRE2_SIZE * lengthptr )
362+ match_ref (PCRE2_SIZE offset , BOOL caseless , int caseopts , heapframe * F ,
363+ match_block * mb , PCRE2_SIZE * lengthptr )
363364{
364365PCRE2_SPTR p ;
365366PCRE2_SIZE length ;
@@ -389,6 +390,7 @@ if (caseless)
389390 {
390391#if defined SUPPORT_UNICODE
391392 BOOL utf = (mb -> poptions & PCRE2_UTF ) != 0 ;
393+ BOOL caseless_restrict = (caseopts & REFI_FLAG_CASELESS_RESTRICT ) != 0 ;
392394
393395 if (utf || (mb -> poptions & PCRE2_UCP ) != 0 )
394396 {
@@ -424,6 +426,11 @@ if (caseless)
424426 if (c != d && c != (uint32_t )((int )d + ur -> other_case ))
425427 {
426428 const uint32_t * pp = PRIV (ucd_caseless_sets ) + ur -> caseset ;
429+
430+ /* When PCRE2_EXTRA_CASELESS_RESTRICT is set, ignore any caseless sets
431+ that start with an ASCII character. */
432+ if (caseless_restrict && * pp < 128 ) return -1 ; /* No match */
433+
427434 for (;;)
428435 {
429436 if (c < * pp ) return -1 ; /* No match */
@@ -5006,16 +5013,18 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
50065013#define Lmin F->temp_32[0]
50075014#define Lmax F->temp_32[1]
50085015#define Lcaseless F->temp_32[2]
5016+ #define Lcaseopts F->temp_32[3]
50095017#define Lstart F->temp_sptr[0]
50105018#define Loffset F->temp_size
50115019
50125020 case OP_DNREF :
50135021 case OP_DNREFI :
50145022 Lcaseless = (Fop == OP_DNREFI );
5023+ Lcaseopts = (Fop == OP_DNREFI )? Fecode [1 + 2 * IMM2_SIZE ] : 0 ;
50155024 {
50165025 int count = GET2 (Fecode , 1 + IMM2_SIZE );
50175026 PCRE2_SPTR slot = mb -> name_table + GET2 (Fecode , 1 ) * mb -> name_entry_size ;
5018- Fecode += 1 + 2 * IMM2_SIZE ;
5027+ Fecode += 1 + 2 * IMM2_SIZE + ( Fop == OP_DNREFI ? 1 : 0 ) ;
50195028
50205029 while (count -- > 0 )
50215030 {
@@ -5029,8 +5038,9 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
50295038 case OP_REF :
50305039 case OP_REFI :
50315040 Lcaseless = (Fop == OP_REFI );
5041+ Lcaseopts = (Fop == OP_REFI )? Fecode [1 + IMM2_SIZE ] : 0 ;
50325042 Loffset = (GET2 (Fecode , 1 ) << 1 ) - 2 ;
5033- Fecode += 1 + IMM2_SIZE ;
5043+ Fecode += 1 + IMM2_SIZE + ( Fop == OP_REFI ? 1 : 0 ) ;
50345044
50355045 /* Set up for repetition, or handle the non-repeated case. The maximum and
50365046 minimum must be in the heap frame, but as they are short-term values, we
@@ -5062,7 +5072,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
50625072
50635073 default : /* No repeat follows */
50645074 {
5065- rrc = match_ref (Loffset , Lcaseless , F , mb , & length );
5075+ rrc = match_ref (Loffset , Lcaseless , Lcaseopts , F , mb , & length );
50665076 if (rrc != 0 )
50675077 {
50685078 if (rrc > 0 ) Feptr = mb -> end_subject ; /* Partial match */
@@ -5096,7 +5106,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
50965106 for (i = 1 ; i <= Lmin ; i ++ )
50975107 {
50985108 PCRE2_SIZE slength ;
5099- rrc = match_ref (Loffset , Lcaseless , F , mb , & slength );
5109+ rrc = match_ref (Loffset , Lcaseless , Lcaseopts , F , mb , & slength );
51005110 if (rrc != 0 )
51015111 {
51025112 if (rrc > 0 ) Feptr = mb -> end_subject ; /* Partial match */
@@ -5120,7 +5130,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
51205130 RMATCH (Fecode , RM20 );
51215131 if (rrc != MATCH_NOMATCH ) RRETURN (rrc );
51225132 if (Lmin ++ >= Lmax ) RRETURN (MATCH_NOMATCH );
5123- rrc = match_ref (Loffset , Lcaseless , F , mb , & slength );
5133+ rrc = match_ref (Loffset , Lcaseless , Lcaseopts , F , mb , & slength );
51245134 if (rrc != 0 )
51255135 {
51265136 if (rrc > 0 ) Feptr = mb -> end_subject ; /* Partial match */
@@ -5145,7 +5155,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
51455155 for (i = Lmin ; i < Lmax ; i ++ )
51465156 {
51475157 PCRE2_SIZE slength ;
5148- rrc = match_ref (Loffset , Lcaseless , F , mb , & slength );
5158+ rrc = match_ref (Loffset , Lcaseless , Lcaseopts , F , mb , & slength );
51495159 if (rrc != 0 )
51505160 {
51515161 /* Can't use CHECK_PARTIAL because we don't want to update Feptr in
@@ -5196,7 +5206,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
51965206 for (i = Lmin ; i < Lmax ; i ++ )
51975207 {
51985208 PCRE2_SIZE slength ;
5199- (void )match_ref (Loffset , Lcaseless , F , mb , & slength );
5209+ (void )match_ref (Loffset , Lcaseless , Lcaseopts , F , mb , & slength );
52005210 Feptr += slength ;
52015211 }
52025212 }
0 commit comments