Allow any punctuation (except :) as separator in s/x/y/, not only

/. From JINNOUCHI Yasushi in GitHub issue 1386.
pull/1389/head
nicm 2018-06-27 17:36:10 +00:00
parent 97738921cd
commit a14aa788d4
1 changed files with 8 additions and 6 deletions

View File

@ -19,6 +19,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <ctype.h>
#include <errno.h> #include <errno.h>
#include <fnmatch.h> #include <fnmatch.h>
#include <libgen.h> #include <libgen.h>
@ -891,7 +892,7 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
char **buf, size_t *len, size_t *off) char **buf, size_t *len, size_t *off)
{ {
struct window_pane *wp = ft->wp; struct window_pane *wp = ft->wp;
char *copy, *copy0, *endptr, *ptr, *found, *new; char *copy, *copy0, *endptr, *ptr, *found, *new, sep;
char *value, *from = NULL, *to = NULL, *left, *right; char *value, *from = NULL, *to = NULL, *left, *right;
size_t valuelen, newlen, fromlen, tolen, used; size_t valuelen, newlen, fromlen, tolen, used;
long limit = 0; long limit = 0;
@ -975,20 +976,21 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
copy += 2; copy += 2;
break; break;
case 's': case 's':
if (copy[1] != '/') sep = copy[1];
if (sep == ':' || !ispunct((u_char)sep))
break; break;
from = copy + 2; from = copy + 2;
for (copy = from; *copy != '\0' && *copy != '/'; copy++) for (copy = from; *copy != '\0' && *copy != sep; copy++)
/* nothing */; /* nothing */;
if (copy[0] != '/' || copy == from) { if (copy[0] != sep || copy == from) {
copy = copy0; copy = copy0;
break; break;
} }
copy[0] = '\0'; copy[0] = '\0';
to = copy + 1; to = copy + 1;
for (copy = to; *copy != '\0' && *copy != '/'; copy++) for (copy = to; *copy != '\0' && *copy != sep; copy++)
/* nothing */; /* nothing */;
if (copy[0] != '/' || copy[1] != ':') { if (copy[0] != sep || copy[1] != ':') {
copy = copy0; copy = copy0;
break; break;
} }