Merge pull request #1582 from shdown/allow-escaping-backslashes
Allow escaping backslashes
This commit is contained in:
commit
fb0573e183
|
@ -516,7 +516,7 @@ void handle_button(xcb_button_press_event_t *event) {
|
||||||
size_t namelen = 0;
|
size_t namelen = 0;
|
||||||
const char *utf8_name = cur_ws->canonical_name;
|
const char *utf8_name = cur_ws->canonical_name;
|
||||||
for (const char *walk = utf8_name; *walk != '\0'; walk++) {
|
for (const char *walk = utf8_name; *walk != '\0'; walk++) {
|
||||||
if (*walk == '"')
|
if (*walk == '"' || *walk == '\\')
|
||||||
num_quotes++;
|
num_quotes++;
|
||||||
/* While we’re looping through the name anyway, we can save one
|
/* While we’re looping through the name anyway, we can save one
|
||||||
* strlen(). */
|
* strlen(). */
|
||||||
|
@ -530,7 +530,7 @@ void handle_button(xcb_button_press_event_t *event) {
|
||||||
for (inpos = 0, outpos = strlen("workspace \"");
|
for (inpos = 0, outpos = strlen("workspace \"");
|
||||||
inpos < namelen;
|
inpos < namelen;
|
||||||
inpos++, outpos++) {
|
inpos++, outpos++) {
|
||||||
if (utf8_name[inpos] == '"') {
|
if (utf8_name[inpos] == '"' || utf8_name[inpos] == '\\') {
|
||||||
buffer[outpos] = '\\';
|
buffer[outpos] = '\\';
|
||||||
outpos++;
|
outpos++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -216,8 +216,9 @@ char *parse_string(const char **walk, bool as_word) {
|
||||||
if (**walk == '"') {
|
if (**walk == '"') {
|
||||||
beginning++;
|
beginning++;
|
||||||
(*walk)++;
|
(*walk)++;
|
||||||
while (**walk != '\0' && (**walk != '"' || *(*walk - 1) == '\\'))
|
for (; **walk != '\0' && **walk != '"'; (*walk)++)
|
||||||
(*walk)++;
|
if (**walk == '\\' && *(*walk + 1) != '\0')
|
||||||
|
(*walk)++;
|
||||||
} else {
|
} else {
|
||||||
if (!as_word) {
|
if (!as_word) {
|
||||||
/* For a string (starting with 's'), the delimiters are
|
/* For a string (starting with 's'), the delimiters are
|
||||||
|
@ -248,10 +249,10 @@ char *parse_string(const char **walk, bool as_word) {
|
||||||
for (inpos = 0, outpos = 0;
|
for (inpos = 0, outpos = 0;
|
||||||
inpos < (*walk - beginning);
|
inpos < (*walk - beginning);
|
||||||
inpos++, outpos++) {
|
inpos++, outpos++) {
|
||||||
/* We only handle escaped double quotes to not break
|
/* We only handle escaped double quotes and backslashes to not break
|
||||||
* backwards compatibility with people using \w in
|
* backwards compatibility with people using \w in regular expressions
|
||||||
* regular expressions etc. */
|
* etc. */
|
||||||
if (beginning[inpos] == '\\' && beginning[inpos + 1] == '"')
|
if (beginning[inpos] == '\\' && (beginning[inpos + 1] == '"' || beginning[inpos + 1] == '\\'))
|
||||||
inpos++;
|
inpos++;
|
||||||
str[outpos] = beginning[inpos];
|
str[outpos] = beginning[inpos];
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,7 +156,7 @@ is(parser_calls('move something to somewhere'),
|
||||||
'error for unknown literal ok');
|
'error for unknown literal ok');
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# 3: Verify that escaping of double quotes works correctly
|
# 3: Verify that escaping works correctly
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
is(parser_calls('workspace "foo"'),
|
is(parser_calls('workspace "foo"'),
|
||||||
|
@ -171,6 +171,18 @@ is(parser_calls('workspace "foo \"bar"'),
|
||||||
'cmd_workspace_name(foo "bar)',
|
'cmd_workspace_name(foo "bar)',
|
||||||
'Command with escaped double quotes ok');
|
'Command with escaped double quotes ok');
|
||||||
|
|
||||||
|
is(parser_calls('workspace "foo \\'),
|
||||||
|
'cmd_workspace_name(foo \\)',
|
||||||
|
'Command with single backslash in the end ok');
|
||||||
|
|
||||||
|
is(parser_calls('workspace "foo\\\\bar"'),
|
||||||
|
'cmd_workspace_name(foo\\bar)',
|
||||||
|
'Command with escaped backslashes ok');
|
||||||
|
|
||||||
|
is(parser_calls('workspace "foo\\\\\\"bar"'),
|
||||||
|
'cmd_workspace_name(foo\\"bar)',
|
||||||
|
'Command with escaped double quotes after escaped backslashes ok');
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# 4: Verify that resize commands with a "px or ppt"-construction are parsed
|
# 4: Verify that resize commands with a "px or ppt"-construction are parsed
|
||||||
# correctly
|
# correctly
|
||||||
|
|
Loading…
Reference in New Issue