--- a/src/json.c Sat Jan 11 12:56:54 2025 +0100 +++ b/src/json.c Sun Jan 12 13:04:32 2025 +0100 @@ -386,7 +386,7 @@ return result; } -static cxmutstr escape_string(cxmutstr str) { +static cxmutstr escape_string(cxmutstr str, bool escape_slash) { // note: this function produces the string without enclosing quotes // the reason is that we don't want to allocate memory just for that CxBuffer buf = {0}; @@ -396,8 +396,7 @@ bool escape = !isprint(str.ptr[i]) || str.ptr[i] == '\\' || str.ptr[i] == '"' - // TODO: make escaping slash optional - || str.ptr[i] == '/'; + || (escape_slash && str.ptr[i] == '/'); if (all_printable && escape) { size_t capa = str.length + 32; @@ -1058,7 +1057,8 @@ true, 6, false, - 4 + 4, + false }; } @@ -1068,7 +1068,8 @@ true, 6, use_spaces, - 4 + 4, + false }; } @@ -1149,7 +1150,7 @@ // the name actual += wfunc("\"", 1, 1, target); - cxmutstr name = escape_string(member->name); + cxmutstr name = escape_string(member->name, settings->escape_slash); actual += wfunc(name.ptr, 1, name.length, target); if (name.ptr != member->name.ptr) { cx_strfree(&name); @@ -1219,7 +1220,7 @@ } case CX_JSON_STRING: { actual += wfunc("\"", 1, 1, target); - cxmutstr str = escape_string(value->value.string); + cxmutstr str = escape_string(value->value.string, settings->escape_slash); actual += wfunc(str.ptr, 1, str.length, target); if (str.ptr != value->value.string.ptr) { cx_strfree(&str);