[libxml2] Fix caret in regexp character group



commit 7d6837ba0e282e94eb8630ad791f427e44a57491
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Sun Oct 25 20:21:43 2020 +0100

    Fix caret in regexp character group
    
    Apply Per Hedeland's patch from
    
        https://bugzilla.gnome.org/show_bug.cgi?id=779751
    
    Fixes #188.

 xmlregexp.c | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)
---
diff --git a/xmlregexp.c b/xmlregexp.c
index f971f0c82..40dabb203 100644
--- a/xmlregexp.c
+++ b/xmlregexp.c
@@ -5155,7 +5155,7 @@ xmlFAParsePosCharGroup(xmlRegParserCtxtPtr ctxt) {
        } else {
            xmlFAParseCharRange(ctxt);
        }
-    } while ((CUR != ']') && (CUR != '^') && (CUR != '-') &&
+    } while ((CUR != ']') && (CUR != '-') &&
              (CUR != 0) && (ctxt->error == 0));
 }
 
@@ -5170,34 +5170,31 @@ xmlFAParsePosCharGroup(xmlRegParserCtxtPtr ctxt) {
  */
 static void
 xmlFAParseCharGroup(xmlRegParserCtxtPtr ctxt) {
-    int n = ctxt->neg;
-    while ((CUR != ']') && (ctxt->error == 0)) {
-       if (CUR == '^') {
-           int neg = ctxt->neg;
+    int neg = ctxt->neg;
 
-           NEXT;
-           ctxt->neg = !ctxt->neg;
-           xmlFAParsePosCharGroup(ctxt);
-           ctxt->neg = neg;
-       } else if ((CUR == '-') && (NXT(1) == '[')) {
-           int neg = ctxt->neg;
-           ctxt->neg = 2;
+    if (CUR == '^') {
+       NEXT;
+       ctxt->neg = !ctxt->neg;
+       xmlFAParsePosCharGroup(ctxt);
+       ctxt->neg = neg;
+    }
+    while ((CUR != ']') && (ctxt->error == 0)) {
+       if ((CUR == '-') && (NXT(1) == '[')) {
            NEXT;       /* eat the '-' */
            NEXT;       /* eat the '[' */
+           ctxt->neg = 2;
            xmlFAParseCharGroup(ctxt);
+           ctxt->neg = neg;
            if (CUR == ']') {
                NEXT;
            } else {
                ERROR("charClassExpr: ']' expected");
-               break;
            }
-           ctxt->neg = neg;
            break;
-       } else if (CUR != ']') {
+       } else {
            xmlFAParsePosCharGroup(ctxt);
        }
     }
-    ctxt->neg = n;
 }
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]