From a69f1aaf21b8dfff1dccb88bfabe4fa08f8548cd Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Wed, 2 Dec 2015 07:53:00 +1100 Subject: [PATCH] Quote regex chars when they are included from doc into search string. Also handle unicode search properly. Signed-off-by: NeilBrown --- emacs-search.c | 10 ++++++++-- rexel.c | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/emacs-search.c b/emacs-search.c index d48ff835..4ecef747 100644 --- a/emacs-search.c +++ b/emacs-search.c @@ -102,6 +102,8 @@ DEF_CMD(search_add) struct doc *d = doc_from_pane(esi->target); wint_t wch; char b[5]; + mbstate_t ps = {0}; + int l; struct cmd_info ci2 = {0}; if (!d) @@ -121,8 +123,12 @@ DEF_CMD(search_add) return 1; } /* FIXME utf-8! and quote regexp chars */ - b[0] = wch; - b[1] = 0; + if (strchr("|*+?{}()?^$\\", wch)) { + b[0] = '\\'; + l = wcrtomb(b+1, wch, &ps) + 1; + } else + l = wcrtomb(b, wch, &ps); + b[l] = 0; ci2.key = "Replace"; ci2.str = b; ci2.numeric = 1; diff --git a/rexel.c b/rexel.c index 329c7cbf..de38803b 100644 --- a/rexel.c +++ b/rexel.c @@ -916,7 +916,7 @@ static int parse_atom(struct parse_state *st) st->patn++; ch = *st->patn; switch (ch) { - /* These just fall through are are interpreted literally */ + /* These just fall through and are interpreted literally */ case '^': case '.': case '[': @@ -928,6 +928,7 @@ static int parse_atom(struct parse_state *st) case '+': case '?': case '{': + case '}': case '\\': break; /* These are simple translations */ -- 2.39.5