diff --git a/Compiler/src/Compiler.cpp b/Compiler/src/Compiler.cpp index cc605e87..cacd3266 100644 --- a/Compiler/src/Compiler.cpp +++ b/Compiler/src/Compiler.cpp @@ -1480,14 +1480,24 @@ struct Compiler void compileExprInterpString(AstExprInterpString* expr, uint8_t target, bool targetTemp) { - // INTERP TODO: percent sign escape std::string formatString; unsigned int stringsLeft = expr->strings.size; for (AstArray const& string : expr->strings) { - formatString += string.data; + std::string stringEscaped(string.data); + + for (size_t characterIndex = 0; characterIndex < stringEscaped.size(); ++characterIndex) + { + if (stringEscaped[characterIndex] == '%') + { + stringEscaped.insert(characterIndex, 1, '%'); + characterIndex++; + } + } + + formatString += stringEscaped; stringsLeft--; diff --git a/tests/conformance/stringinterp.lua b/tests/conformance/stringinterp.lua index 135fbf1b..d59427f3 100644 --- a/tests/conformance/stringinterp.lua +++ b/tests/conformance/stringinterp.lua @@ -43,8 +43,8 @@ assertEq(`Hello {`from inside {"a nested string"}`}`, "Hello from inside a neste assertEq(`1 {`2 {`3 {4}`}`}`, "1 2 3 4") --- local health = 50 --- assert(`You have {health}% health` == "You have 50% health") +local health = 50 +assert(`You have {health}% health` == "You have 50% health") -- INTERP TODO: Test with shadowing `string` (both as a string and not)