size_t namelen = 0;
const char *utf8_name = cur_ws->canonical_name;
for (const char *walk = utf8_name; *walk != '\0'; walk++) {
- if (*walk == '"')
+ if (*walk == '"' || *walk == '\\')
num_quotes++;
/* While we’re looping through the name anyway, we can save one
* strlen(). */
for (inpos = 0, outpos = strlen("workspace \"");
inpos < namelen;
inpos++, outpos++) {
- if (utf8_name[inpos] == '"') {
+ if (utf8_name[inpos] == '"' || utf8_name[inpos] == '\\') {
buffer[outpos] = '\\';
outpos++;
}
if (**walk == '"') {
beginning++;
(*walk)++;
- while (**walk != '\0' && (**walk != '"' || *(*walk - 1) == '\\'))
- (*walk)++;
+ for (; **walk != '\0' && **walk != '"'; (*walk)++)
+ if (**walk == '\\' && *(*walk + 1) != '\0')
+ (*walk)++;
} else {
if (!as_word) {
/* For a string (starting with 's'), the delimiters are
for (inpos = 0, outpos = 0;
inpos < (*walk - beginning);
inpos++, outpos++) {
- /* We only handle escaped double quotes to not break
- * backwards compatibility with people using \w in
- * regular expressions etc. */
- if (beginning[inpos] == '\\' && beginning[inpos + 1] == '"')
+ /* We only handle escaped double quotes and backslashes to not break
+ * backwards compatibility with people using \w in regular expressions
+ * etc. */
+ if (beginning[inpos] == '\\' && (beginning[inpos + 1] == '"' || beginning[inpos + 1] == '\\'))
inpos++;
str[outpos] = beginning[inpos];
}