aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/regexp.c4
-rw-r--r--src/nvim/regexp_nfa.c19
-rw-r--r--src/nvim/testdir/test_regexp_latin.vim17
3 files changed, 29 insertions, 11 deletions
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c
index a70b150e9b..53479294de 100644
--- a/src/nvim/regexp.c
+++ b/src/nvim/regexp.c
@@ -772,7 +772,7 @@ static int get_equi_class(char_u **pp)
int l = 1;
char_u *p = *pp;
- if (p[1] == '=') {
+ if (p[1] == '=' && p[2] != NUL) {
l = (*mb_ptr2len)(p + 2);
if (p[l + 2] == '=' && p[l + 3] == ']') {
c = utf_ptr2char(p + 2);
@@ -1103,7 +1103,7 @@ static int get_coll_element(char_u **pp)
int l = 1;
char_u *p = *pp;
- if (p[0] != NUL && p[1] == '.') {
+ if (p[0] != NUL && p[1] == '.' && p[2] != NUL) {
l = utfc_ptr2len(p + 2);
if (p[l + 2] == '.' && p[l + 3] == ']') {
c = utf_ptr2char(p + 2);
diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c
index 08ef7da9c1..d34e653058 100644
--- a/src/nvim/regexp_nfa.c
+++ b/src/nvim/regexp_nfa.c
@@ -1691,15 +1691,16 @@ collection:
) {
MB_PTR_ADV(regparse);
- if (*regparse == 'n')
- startc = reg_string ? NL : NFA_NEWL;
- else if (*regparse == 'd'
- || *regparse == 'o'
- || *regparse == 'x'
- || *regparse == 'u'
- || *regparse == 'U'
- ) {
- /* TODO(RE) This needs more testing */
+ if (*regparse == 'n') {
+ startc = (reg_string || emit_range || regparse[1] == '-')
+ ? NL : NFA_NEWL;
+ } else if (*regparse == 'd'
+ || *regparse == 'o'
+ || *regparse == 'x'
+ || *regparse == 'u'
+ || *regparse == 'U'
+ ) {
+ // TODO(RE): This needs more testing
startc = coll_get_char();
got_coll_char = true;
MB_PTR_BACK(old_regparse, regparse);
diff --git a/src/nvim/testdir/test_regexp_latin.vim b/src/nvim/testdir/test_regexp_latin.vim
index 8528412806..eb8f69ef15 100644
--- a/src/nvim/testdir/test_regexp_latin.vim
+++ b/src/nvim/testdir/test_regexp_latin.vim
@@ -30,3 +30,20 @@ func Test_equivalence_re2()
set re=2
call s:equivalence_test()
endfunc
+
+func Test_range_with_newline()
+ new
+ call setline(1, "a")
+ call assert_equal(0, search("[ -*\\n- ]"))
+ call assert_equal(0, search("[ -*\\t-\\n]"))
+ bwipe!
+endfunc
+
+func Test_get_equi_class()
+ new
+ " Incomplete equivalence class caused invalid memory access
+ s/^/[[=
+ call assert_equal(1, search(getline(1)))
+ s/.*/[[.
+ call assert_equal(1, search(getline(1)))
+endfunc