Skip to content

Commit a577fc9

Browse files
committed
handle regexps with missing \E (quick fix for zyedidia#3700)
1 parent 9183fbe commit a577fc9

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

internal/buffer/search.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,21 @@ func findLineParams(b *Buffer, start, end Loc, i int, r *regexp.Regexp) ([]byte,
4141
}
4242
}
4343

44-
if padMode == padStart {
45-
r = regexp.MustCompile(".(?:" + r.String() + ")")
46-
} else if padMode == padEnd {
47-
r = regexp.MustCompile("(?:" + r.String() + ").")
48-
} else if padMode == padStart|padEnd {
49-
r = regexp.MustCompile(".(?:" + r.String() + ").")
44+
if padMode != 0 {
45+
re, err := regexp.Compile(r.String() + `\E`)
46+
if err == nil {
47+
// r contains \Q without closing \E
48+
r = re
49+
}
50+
51+
if padMode == padStart {
52+
r = regexp.MustCompile(".(?:" + r.String() + ")")
53+
} else if padMode == padEnd {
54+
r = regexp.MustCompile("(?:" + r.String() + ").")
55+
} else {
56+
// padMode == padStart|padEnd
57+
r = regexp.MustCompile(".(?:" + r.String() + ").")
58+
}
5059
}
5160

5261
return l, charpos, padMode, r

0 commit comments

Comments
 (0)