From 2880cfd2f3850392c35a45f988fd5cdb6d1eaff8 Mon Sep 17 00:00:00 2001 From: "Marian W." Date: Sun, 2 Feb 2025 21:47:21 +0100 Subject: [PATCH] Fix bug where escape sequences in string arrays are not parsed correctly --- minipp/minipp.hpp | 9 +++++++++ minipp/test.mini | 3 ++- minipp/test_out.mini | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/minipp/minipp.hpp b/minipp/minipp.hpp index 912c398..02fa61a 100644 --- a/minipp/minipp.hpp +++ b/minipp/minipp.hpp @@ -547,7 +547,16 @@ minipp::EResult minipp::MiniPPFile::Values::ArrayValue::Parse(const std::string& if (isInString) { if (c == '\\') + { + if (i + 1 >= str.size()) + { + PP_COUT("Syntax error: Bad escape sequence: '\\' at end of string"); + return EResult::FormatError; + } + currentElement += c; + currentElement += str[i + 1]; ++i; + } else if (c == '"') { isInString = false; diff --git a/minipp/test.mini b/minipp/test.mini index 7c63239..94202f7 100644 --- a/minipp/test.mini +++ b/minipp/test.mini @@ -1,10 +1,11 @@ [game] -name = "Test Game" +name = "Test Game\nNext Line" version = "1.0.0" year = 2025 completionPercentage = 50.0f # Should only be true if completionPercentage is 100 is_completed = false +testargs = ["this is a \"test\"", "this is\n the next line"] # This section is about # the settings of a game window diff --git a/minipp/test_out.mini b/minipp/test_out.mini index a3e12e7..6fc1222 100644 --- a/minipp/test_out.mini +++ b/minipp/test_out.mini @@ -1,7 +1,8 @@ [game] -name = "Test Game" +name = "Test Game\nNext Line" completionPercentage = 50.000000 version = "1.0.0" +testargs = ["this is a \"test\"", "this is\n the next line"] year = 2025 # Should only be true if completionPercentage is 100 is_completed = false