mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-05-06 06:47:17 -04:00
tokenize: handle escaped quotes
We only support escaping quotes inside a quote, and only of the same type as the enclosing quote. I.e. "double quote \"escaped double quote\"" But not "double quote \'invalid escaped single quote\'"
This commit is contained in:
parent
3b2492029e
commit
50bd51c4d4
2 changed files with 14 additions and 1 deletions
|
|
@ -18,6 +18,8 @@
|
||||||
* [LICENSE](LICENSE), [README.md](README.md) and
|
* [LICENSE](LICENSE), [README.md](README.md) and
|
||||||
[CHANGELOG.md](CHANGELOG.md) are now installed to
|
[CHANGELOG.md](CHANGELOG.md) are now installed to
|
||||||
`${datadir}/doc/foot`.
|
`${datadir}/doc/foot`.
|
||||||
|
* Support for escaping quotes in **pipe-visible** and
|
||||||
|
**pipe-scrollback** commands.
|
||||||
|
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
|
||||||
13
tokenize.c
13
tokenize.c
|
|
@ -38,10 +38,11 @@ tokenize_cmdline(char *cmdline, char ***argv)
|
||||||
char delim = first_token_is_quoted ? cmdline[0] : ' ';
|
char delim = first_token_is_quoted ? cmdline[0] : ' ';
|
||||||
|
|
||||||
char *p = first_token_is_quoted ? &cmdline[1] : &cmdline[0];
|
char *p = first_token_is_quoted ? &cmdline[1] : &cmdline[0];
|
||||||
|
char *search_start = p;
|
||||||
|
|
||||||
size_t idx = 0;
|
size_t idx = 0;
|
||||||
while (*p != '\0') {
|
while (*p != '\0') {
|
||||||
char *end = strchr(p, delim);
|
char *end = strchr(search_start, delim);
|
||||||
if (end == NULL) {
|
if (end == NULL) {
|
||||||
if (delim != ' ') {
|
if (delim != ' ') {
|
||||||
LOG_ERR("unterminated %s quote", delim == '"' ? "double" : "single");
|
LOG_ERR("unterminated %s quote", delim == '"' ? "double" : "single");
|
||||||
|
|
@ -58,6 +59,15 @@ tokenize_cmdline(char *cmdline, char ***argv)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (end > p && *(end - 1) == '\\') {
|
||||||
|
/* Escaped quote, remove one level of escaping and
|
||||||
|
* continue searching for "our" closing quote */
|
||||||
|
memmove(end - 1, end, strlen(end));
|
||||||
|
end[strlen(end) - 1] = '\0';
|
||||||
|
search_start = end;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
*end = '\0';
|
*end = '\0';
|
||||||
|
|
||||||
if (!push_argv(argv, &argv_size, p, &idx))
|
if (!push_argv(argv, &argv_size, p, &idx))
|
||||||
|
|
@ -75,6 +85,7 @@ tokenize_cmdline(char *cmdline, char ***argv)
|
||||||
p++;
|
p++;
|
||||||
} else
|
} else
|
||||||
delim = ' ';
|
delim = ' ';
|
||||||
|
search_start = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!push_argv(argv, &argv_size, NULL, &idx))
|
if (!push_argv(argv, &argv_size, NULL, &idx))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue