summaryrefslogtreecommitdiff
path: root/src/regex-emacs.c
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2020-02-26 14:46:01 +0100
committerMattias EngdegÄrd <mattiase@acm.org>2020-02-26 22:09:17 +0100
commit8d5e8cddab732ac90e9ae930c63f7830f9dab24f (patch)
tree6db0e10a351f5d1292a67f4c02c3eefeb00b9714 /src/regex-emacs.c
parent2261f89324997351a41d8f12af513b8ec5e9c26b (diff)
downloademacs-8d5e8cddab732ac90e9ae930c63f7830f9dab24f.tar.gz
Signal an error for the regexp "[:alnum:]"
Omitting the extra brackets is a common mistake; see discussion at https://lists.gnu.org/archive/html/emacs-devel/2020-02/msg00215.html * src/regex-emacs.c (reg_errcode_t, re_error_msgid): Add REG_ECLASSBR. (regex_compile): Check for the mistake. * test/src/regex-emacs-tests.el (regexp-invalid): Test. * etc/NEWS: Announce.
Diffstat (limited to 'src/regex-emacs.c')
-rw-r--r--src/regex-emacs.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/regex-emacs.c b/src/regex-emacs.c
index 694431c95e2..38824370e05 100644
--- a/src/regex-emacs.c
+++ b/src/regex-emacs.c
@@ -818,7 +818,8 @@ typedef enum
REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */
REG_ERPAREN, /* Unmatched ) or \); not returned from regcomp. */
REG_ERANGEX, /* Range striding over charsets. */
- REG_ESIZEBR /* n or m too big in \{n,m\} */
+ REG_ESIZEBR, /* n or m too big in \{n,m\} */
+ REG_ECLASSBR, /* Missing [] around [:class:]. */
} reg_errcode_t;
static const char *re_error_msgid[] =
@@ -842,6 +843,7 @@ static const char *re_error_msgid[] =
[REG_ERPAREN] = "Unmatched ) or \\)",
[REG_ERANGEX ] = "Range striding over charsets",
[REG_ESIZEBR ] = "Invalid content of \\{\\}",
+ [REG_ECLASSBR] = "Class syntax is [[:digit:]]; missing brackets",
};
/* For 'regs_allocated'. */
@@ -2000,6 +2002,23 @@ regex_compile (re_char *pattern, ptrdiff_t size,
laststart = b;
+ /* Check for the mistake of forgetting the extra square brackets,
+ as in "[:alpha:]". */
+ if (*p == ':')
+ {
+ re_char *q = p + 1;
+ while (q != pend && *q != ']')
+ {
+ if (*q == ':')
+ {
+ if (q + 1 != pend && q[1] == ']' && q > p + 1)
+ FREE_STACK_RETURN (REG_ECLASSBR);
+ break;
+ }
+ q++;
+ }
+ }
+
/* Test '*p == '^' twice, instead of using an if
statement, so we need only one BUF_PUSH. */
BUF_PUSH (*p == '^' ? charset_not : charset);