mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
json: strip spaces and special chars when copying objects
When turning an object into a string, strip out all special chars and duplicate spaces.
This commit is contained in:
parent
f1e56b2317
commit
0be2959f11
1 changed files with 37 additions and 23 deletions
|
|
@ -287,10 +287,23 @@ static inline int spa_json_parse_string(const char *val, int len, char *result)
|
||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
if (!spa_json_is_string(val, len)) {
|
if (!spa_json_is_string(val, len)) {
|
||||||
strncpy(result, val, len);
|
bool skip = false;
|
||||||
result[len] = '\0';
|
for (p = val; p < val + len; p++) {
|
||||||
return 1;
|
switch (*p) {
|
||||||
|
case '\n': case '\r': case '\b': case '\t': case '\f':
|
||||||
|
break;
|
||||||
|
case ' ':
|
||||||
|
if (!skip)
|
||||||
|
*result++ = *p;
|
||||||
|
skip = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
*result++ = *p;
|
||||||
|
skip = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
for (p = val+1; p < val + len; p++) {
|
for (p = val+1; p < val + len; p++) {
|
||||||
if (*p == '\\') {
|
if (*p == '\\') {
|
||||||
p++;
|
p++;
|
||||||
|
|
@ -311,7 +324,8 @@ static inline int spa_json_parse_string(const char *val, int len, char *result)
|
||||||
} else
|
} else
|
||||||
*result++ = *p;
|
*result++ = *p;
|
||||||
}
|
}
|
||||||
*result++ = '\0';
|
}
|
||||||
|
*result = '\0';
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue