This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
4 bugs in Test::More
[perl5.git] / regcomp.c
index e49c46b..dedcd00 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -69,7 +69,8 @@
  *
  ****    Alterations to Henry's code are...
  ****
- ****    Copyright (c) 1991-2002, Larry Wall
+ ****    Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+ ****    2000, 2001, 2002, 2003, by Larry Wall and others
  ****
  ****    You may distribute under the terms of either the GNU General Public
  ****    License or the Artistic License, as specified in the README file.
@@ -471,7 +472,7 @@ S_scan_commit(pTHX_ RExC_state_t *pRExC_state, scan_data_t *data)
     STRLEN old_l = CHR_SVLEN(*data->longest);
 
     if ((l >= old_l) && ((l > old_l) || (data->flags & SF_BEFORE_EOL))) {
-       sv_setsv(*data->longest, data->last_found);
+       SvSetMagicSV(*data->longest, data->last_found);
        if (*data->longest == data->longest_fixed) {
            data->offset_fixed = l ? data->last_start_min : data->pos_min;
            if (data->flags & SF_BEFORE_EOL)
@@ -495,6 +496,13 @@ S_scan_commit(pTHX_ RExC_state_t *pRExC_state, scan_data_t *data)
        }
     }
     SvCUR_set(data->last_found, 0);
+    {
+       SV * sv = data->last_found;
+       MAGIC *mg =
+           SvUTF8(sv) && SvMAGICAL(sv) ? mg_find(sv, PERL_MAGIC_utf8) : NULL;
+       if (mg && mg->mg_len > 0)
+           mg->mg_len = 0;
+    }
     data->last_end = -1;
     data->flags &= ~SF_BEFORE_EOL;
 }
@@ -568,14 +576,17 @@ S_cl_and(pTHX_ struct regnode_charclass_class *cl,
     if (!(and_with->flags & ANYOF_EOS))
        cl->flags &= ~ANYOF_EOS;
 
-    if (cl->flags & ANYOF_UNICODE_ALL && and_with->flags & ANYOF_UNICODE) {
+    if (cl->flags & ANYOF_UNICODE_ALL && and_with->flags & ANYOF_UNICODE &&
+       !(and_with->flags & ANYOF_INVERT)) {
        cl->flags &= ~ANYOF_UNICODE_ALL;
        cl->flags |= ANYOF_UNICODE;
        ARG_SET(cl, ARG(and_with));
     }
-    if (!(and_with->flags & ANYOF_UNICODE_ALL))
+    if (!(and_with->flags & ANYOF_UNICODE_ALL) &&
+       !(and_with->flags & ANYOF_INVERT))
        cl->flags &= ~ANYOF_UNICODE_ALL;
-    if (!(and_with->flags & (ANYOF_UNICODE|ANYOF_UNICODE_ALL)))
+    if (!(and_with->flags & (ANYOF_UNICODE|ANYOF_UNICODE_ALL)) &&
+       !(and_with->flags & ANYOF_INVERT))
        cl->flags &= ~ANYOF_UNICODE;
 }
 
@@ -913,6 +924,14 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp, I32 *deltap, reg
                        ? I32_MAX : data->pos_min + data->pos_delta;
                }
                sv_catpvn(data->last_found, STRING(scan), STR_LEN(scan));
+               {
+                   SV * sv = data->last_found;
+                   MAGIC *mg = SvUTF8(sv) && SvMAGICAL(sv) ?
+                       mg_find(sv, PERL_MAGIC_utf8) : NULL;
+                   if (mg && mg->mg_len >= 0)
+                       mg->mg_len += utf8_length((U8*)STRING(scan),
+                                                 (U8*)STRING(scan)+STR_LEN(scan));
+               }
                if (UTF)
                    SvUTF8_on(data->last_found);
                data->last_end = data->pos_min + l;
@@ -1283,6 +1302,14 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp, I32 *deltap, reg
                                SvCUR_set(data->last_found,
                                          SvCUR(data->last_found) - l);
                                sv_catsv(data->last_found, last_str);
+                               {
+                                   SV * sv = data->last_found;
+                                   MAGIC *mg =
+                                       SvUTF8(sv) && SvMAGICAL(sv) ?
+                                       mg_find(sv, PERL_MAGIC_utf8) : NULL;
+                                   if (mg && mg->mg_len >= 0)
+                                       mg->mg_len += CHR_SVLEN(last_str);
+                               }
                                data->last_end += l * (mincount - 1);
                            }
                        } else {
@@ -2232,8 +2259,10 @@ S_reg(pTHX_ RExC_state_t *pRExC_state, I32 paren, I32 *flagp)
                        FAIL("Eval-group not allowed at runtime, use re 'eval'");
                    if (PL_tainting && PL_tainted)
                        FAIL("Eval-group in insecure regular expression");
+                   if (PL_curcop == &PL_compiling)
+                       PL_cv_has_eval = 1;
                }
-               
+
                nextchar(pRExC_state);
                if (logical) {
                    ret = reg_node(pRExC_state, LOGICAL);
@@ -4714,7 +4743,7 @@ Perl_regprop(pTHX_ SV *sv, regnode *o)
     else if (k == ANYOF) {
        int i, rangestart = -1;
        U8 flags = ANYOF_FLAGS(o);
-       const char * const anyofs[] = { /* Should be syncronized with
+       const char * const anyofs[] = { /* Should be synchronized with
                                         * ANYOF_ #xdefines in regcomp.h */
            "\\w",
            "\\W",