Escape backslashed user input

main
parent d9bae017f2
commit 15e93821b2

@ -438,8 +438,8 @@
"rotation":0,
"visible":true,
"width":32,
"x":3296.66666666667,
"y":3270.33333333333
"x":1524.66666666667,
"y":1114.33333333333
},
{
"class":"",

@ -1193,7 +1193,7 @@ void do_parsing_tests()
error = parse_chatgpt_response(scratch.arena, &e, MD_S8Lit("ACT_give_item(Chalice \""), &a);
assert(error.size > 0);
to_parse = MD_S8Lit("{action: give_item, action_arg: Chalice, speech: \"Here you go\", thoughts: \"Man I'm gonna miss that chalice\", who_i_am: \"Meld\", talking_to: nobody}");
to_parse = MD_S8Lit("{action: give_item, action_arg: \"The Chalice of Gold\", speech: \"Here you go\", thoughts: \"Man I'm gonna miss that chalice\", who_i_am: \"Meld\", talking_to: nobody}");
error = parse_chatgpt_response(scratch.arena, &e, to_parse, &a);
assert(error.size == 0);
assert(a.kind == ACT_give_item);
@ -1982,6 +1982,13 @@ void init(void)
frame_arena = MD_ArenaAlloc();
persistent_arena = MD_ArenaAlloc();
#ifdef DEVTOOLS
Log("Devtools is on!\n");
#else
Log("Devtools is off!\n");
#endif
#ifdef DEVTOOLS
do_metadesk_tests();
do_parsing_tests();

@ -33,7 +33,7 @@ bool character_valid(char c)
MD_String8 escape_for_json(MD_Arena *arena, MD_String8 from)
{
MD_u64 output_size = 0;
#define SHOULD_ESCAPE(c) (c == '"' || c == '\n')
#define SHOULD_ESCAPE(c) (c == '"' || c == '\n' || c == '\\')
for (int i = 0; i < from.size; i++)
{
char c = from.str[i];

Loading…
Cancel
Save