Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lua_cjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,14 @@ static void json_create_config(lua_State *l)
cfg->escape2char['u'] = 'u'; /* Unicode parsing required */
}

/* Whether to escape forward slashes */
static int json_escape_forward_slash(lua_State *l)
{
lua_Integer escape_forward_slash = luaL_checkinteger(l, 1);
char2escape['/'] = escape_forward_slash ? "\\/" : NULL;
Copy link
Owner

@mpx mpx Oct 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CJSON deliberately avoids global options, everything is stored in the state.

Please move char2escape into json_config_t.

return 0;
}

/* ===== ENCODING ===== */

static void json_encode_exception(lua_State *l, json_config_t *cfg, strbuf_t *json, int lindex,
Expand Down Expand Up @@ -1365,6 +1373,7 @@ static int lua_cjson_new(lua_State *l)
{ "encode_keep_buffer", json_cfg_encode_keep_buffer },
{ "encode_invalid_numbers", json_cfg_encode_invalid_numbers },
{ "decode_invalid_numbers", json_cfg_decode_invalid_numbers },
{ "escape_forward_slash", json_escape_forward_slash },
{ "new", lua_cjson_new },
{ NULL, NULL }
};
Expand Down