diff options
author | Billy Su <g4691821@gmail.com> | 2019-03-02 12:38:36 +0800 |
---|---|---|
committer | Billy Su <g4691821@gmail.com> | 2019-03-07 23:48:53 +0800 |
commit | fbd8209286373843b7e9b4151a1432fc4555484d (patch) | |
tree | ed434d5f07975fe4bc4b52ba401254e55b7c523d /src/nvim/regexp.c | |
parent | 570e41fc08ae80421c2458d90cd14d7c3ba65d76 (diff) | |
download | rneovim-fbd8209286373843b7e9b4151a1432fc4555484d.tar.gz rneovim-fbd8209286373843b7e9b4151a1432fc4555484d.tar.bz2 rneovim-fbd8209286373843b7e9b4151a1432fc4555484d.zip |
vim-patch:8.0.0645: no error for illegal back reference in NFA engine
Problem: The new regexp engine does not give an error for using a back
reference where it is not allowed. (Dominique Pelle)
Solution: Check the back reference like the old engine. (closes vim/vim#1774)
https://github.com/vim/vim/commit/1ef9bbe215e13a273e74fccaddd8fc5a42c76b6e
Diffstat (limited to 'src/nvim/regexp.c')
-rw-r--r-- | src/nvim/regexp.c | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 25fa67c112..396b376e39 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -1210,6 +1210,31 @@ char_u *skip_regexp(char_u *startp, int dirc, int magic, char_u **newp) return p; } +/* + * Return TRUE if the back reference is legal. We must have seen the close + * brace. + * TODO: Should also check that we don't refer to something that is repeated + * (+*=): what instance of the repetition should we match? + */ +static int seen_endbrace(int refnum) +{ + if (!had_endbrace[refnum]) { + char_u *p; + + /* Trick: check if "@<=" or "@<!" follows, in which case + * the \1 can appear before the referenced match. */ + for (p = regparse; *p != NUL; ++p) + if (p[0] == '@' && p[1] == '<' && (p[2] == '!' || p[2] == '=')) + break; + + if (*p == NUL) { + EMSG(_("E65: Illegal back reference")); + rc_did_emsg = TRUE; + return FALSE; + } + } + return TRUE; +} /* * bt_regcomp() - compile a regular expression into internal code for the @@ -1928,23 +1953,8 @@ static char_u *regatom(int *flagp) int refnum; refnum = c - Magic('0'); - /* - * Check if the back reference is legal. We must have seen the - * close brace. - * TODO: Should also check that we don't refer to something - * that is repeated (+*=): what instance of the repetition - * should we match? - */ - if (!had_endbrace[refnum]) { - /* Trick: check if "@<=" or "@<!" follows, in which case - * the \1 can appear before the referenced match. */ - for (p = regparse; *p != NUL; ++p) - if (p[0] == '@' && p[1] == '<' - && (p[2] == '!' || p[2] == '=')) - break; - if (*p == NUL) - EMSG_RET_NULL(_("E65: Illegal back reference")); - } + if (!seen_endbrace(refnum)) + return NULL; ret = regnode(BACKREF + refnum); } break; |