From a7c502a756732ec9a1773d6169376bb7b25f4308 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Mon, 11 Mar 2013 22:45:22 +0200 Subject: Fix a bug with ] as real char in regexps. --- re.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 're.c') diff --git a/re.c b/re.c index 711b53e4..4c031777 100644 --- a/re.c +++ b/re.c @@ -564,8 +564,22 @@ again: if (*sp == '[') count++; - else if (*sp == ']') - count--; + /* + * ] as first char after open [ is skipped + * \] is skipped + * [^]] is skipped + */ + if (*sp == ']' && sp > sp2) { + if (sp[-1] != '[' + && sp[-1] != '\\') + ; + else if ((sp - sp2) >= 2 + && sp[-1] == '^' && sp[-2] == '[') + ; + else + count--; + } + if (*sp == '-' && do_lint && ! range_warned && count == 1 && sp[-1] != '[' && sp[1] != ']' && ! isdigit((unsigned char) sp[-1]) && ! isdigit((unsigned char) sp[1]) -- cgit v1.2.3