From 15e93821b29eab8f1297e36311158cd61ce28d55 Mon Sep 17 00:00:00 2001 From: Cameron Reikes Date: Mon, 19 Jun 2023 04:18:00 -0700 Subject: [PATCH] Escape backslashed user input --- assets/new_level.json | 4 ++-- main.c | 9 ++++++++- makeprompt.h | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/assets/new_level.json b/assets/new_level.json index 3e57ff7..136b1e5 100644 --- a/assets/new_level.json +++ b/assets/new_level.json @@ -438,8 +438,8 @@ "rotation":0, "visible":true, "width":32, - "x":3296.66666666667, - "y":3270.33333333333 + "x":1524.66666666667, + "y":1114.33333333333 }, { "class":"", diff --git a/main.c b/main.c index e81c3d7..603ec31 100644 --- a/main.c +++ b/main.c @@ -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(); diff --git a/makeprompt.h b/makeprompt.h index 90e53d2..d3adc80 100644 --- a/makeprompt.h +++ b/makeprompt.h @@ -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];