Escape interpolated strings better

This commit is contained in:
Kampfkarren 2022-07-28 17:45:02 -07:00
parent 3683436dbe
commit c8d7fd171f
2 changed files with 18 additions and 1 deletions

View file

@ -237,7 +237,7 @@ std::string escape(std::string_view s)
for (uint8_t c : s)
{
if (c >= ' ' && c != '\\' && c != '\'' && c != '\"')
if (c >= ' ' && c != '\\' && c != '\'' && c != '\"' && c != '`' && c != '{')
r += c;
else
{
@ -272,6 +272,14 @@ std::string escape(std::string_view s)
case '\"':
r += '\"';
break;
// INTERP CODE REVIEW: This is going to apply it to all escaped strings, not just
// interpolated ones. Is that acceptable, or should this be split into two functions/a toggle?
case '`':
r += '`';
break;
case '{':
r += '{';
break;
case '\\':
r += '\\';
break;

View file

@ -688,4 +688,13 @@ TEST_CASE_FIXTURE(Fixture, "transpile_string_interp")
CHECK_EQ(code, transpile(code, {}, true).code);
}
TEST_CASE_FIXTURE(Fixture, "transpile_string_literal_escape")
{
ScopedFastFlag sff{"LuauInterpolatedStringBaseSupport", true};
std::string code = R"( local _ = ` bracket = \{, backtick = \` = {'ok'} ` )";
CHECK_EQ(code, transpile(code, {}, true).code);
}
TEST_SUITE_END();