From 7d6837ba0e282e94eb8630ad791f427e44a57491 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Sun, 25 Oct 2020 20:21:43 +0100 Subject: 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(-) (limited to 'xmlregexp.c') diff --git a/xmlregexp.c b/xmlregexp.c index f971f0c8..40dabb20 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; } /** -- cgit v1.2.1