Fix string literal parsing escaped whitespace (#2617)

The toolchain misinterprets escaped whitespace characters as unescaped when trimming trailing whitespace on a line. This PR adds a variable to track the length of the string after escaping the most recent escape, making sure we don't backup past that character, whatever it is.

I did try the approach mentioned in #2132 of not backing up `end_of_regular_text` number of characters, but this caused problems on lines like <kbd>tab</kbd> <kbd>space</kbd> <kbd>tab</kbd> (those characters literally, not escaped) where it would leave the first tab since that is processed in a different iteration of that loop.

I added a test case for this bug. I kept getting mixed up in the test output which one was the expected value, so I also changed a variable name there for clarity.

Fixes #2132.
This commit is contained in:
Calvin
2023-02-27 16:05:34 -08:00
committed by GitHub
parent c7aff0a2a9
commit a57c3d9801
2 changed files with 14 additions and 5 deletions
+4 -2
View File
@@ -202,13 +202,15 @@ TEST_F(StringLiteralTest, StringLiteralContents) {
// Trailing whitespace handling.
{"'''\n Hello \\\n World \t \n Bye! \\\n '''",
"Hello World\nBye! "},
{"'''\n\\t\n'''", "\t\n"},
{"'''\n\\t \n'''", "\t\n"},
};
for (auto [test, contents] : testcases) {
for (auto [test, expected] : testcases) {
error_tracker.Reset();
auto value = Parse(test.trim());
EXPECT_FALSE(error_tracker.seen_error()) << "`" << test << "`";
EXPECT_EQ(value, contents);
EXPECT_EQ(value, expected);
}
}