From e97cf5296b0d6adfbd4c2c9598de5a68813807ba Mon Sep 17 00:00:00 2001 From: Justin Meza Date: Sun, 26 Jul 2015 21:39:37 -0700 Subject: [PATCH] escaping the escape character on input (thanks for reporting, @Lucki!) --- interpreter.c | 10 +++++++++- .../5-Input/3-EscapeCharacter/CMakeLists.txt | 2 ++ test/1.3-Tests/5-Input/3-EscapeCharacter/test.in | 2 ++ test/1.3-Tests/5-Input/3-EscapeCharacter/test.lol | 15 +++++++++++++++ test/1.3-Tests/5-Input/3-EscapeCharacter/test.out | 3 +++ .../5-Input/3-EscapeCharacter/test.readme | 3 +++ test/1.3-Tests/5-Input/CMakeLists.txt | 1 + 7 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test/1.3-Tests/5-Input/3-EscapeCharacter/CMakeLists.txt create mode 100644 test/1.3-Tests/5-Input/3-EscapeCharacter/test.in create mode 100644 test/1.3-Tests/5-Input/3-EscapeCharacter/test.lol create mode 100644 test/1.3-Tests/5-Input/3-EscapeCharacter/test.out create mode 100644 test/1.3-Tests/5-Input/3-EscapeCharacter/test.readme diff --git a/interpreter.c b/interpreter.c index 4803263..6b14fcf 100644 --- a/interpreter.c +++ b/interpreter.c @@ -3268,8 +3268,12 @@ ReturnObject *interpretInputStmtNode(StmtNode *node, * but do not store it. */ if (c == EOF || c == (int)'\r' || c == (int)'\n') break; + /* Reserve space to escape colon in input */ + if (c == ':') { + cur++; + } if (cur > size - 1) { - /* Increasing buffer size. */ + /* Increase buffer size */ size *= 2; mem = realloc(temp, sizeof(char) * size); if (!mem) { @@ -3279,6 +3283,10 @@ ReturnObject *interpretInputStmtNode(StmtNode *node, } temp = mem; } + /* Escape colon in input */ + if (c == ':') { + temp[cur - 1] = ':'; + } temp[cur] = (char)c; cur++; } diff --git a/test/1.3-Tests/5-Input/3-EscapeCharacter/CMakeLists.txt b/test/1.3-Tests/5-Input/3-EscapeCharacter/CMakeLists.txt new file mode 100644 index 0000000..4fc5ff5 --- /dev/null +++ b/test/1.3-Tests/5-Input/3-EscapeCharacter/CMakeLists.txt @@ -0,0 +1,2 @@ +INCLUDE(AddLolTest) +ADD_LOL_TEST(3-EscapeCharacter OUTPUT test.out INPUT test.in) diff --git a/test/1.3-Tests/5-Input/3-EscapeCharacter/test.in b/test/1.3-Tests/5-Input/3-EscapeCharacter/test.in new file mode 100644 index 0000000..2ba7407 --- /dev/null +++ b/test/1.3-Tests/5-Input/3-EscapeCharacter/test.in @@ -0,0 +1,2 @@ +:[ ] x [ ] y +: diff --git a/test/1.3-Tests/5-Input/3-EscapeCharacter/test.lol b/test/1.3-Tests/5-Input/3-EscapeCharacter/test.lol new file mode 100644 index 0000000..7f1ffe4 --- /dev/null +++ b/test/1.3-Tests/5-Input/3-EscapeCharacter/test.lol @@ -0,0 +1,15 @@ +HAI 1.3 + I HAS A var1 + GIMMEH var1 + VISIBLE var1 + + I HAS A var2 + GIMMEH var2 + VISIBLE var2 AN " - " AN "::" + BOTH SAEM var2 AN "::", O RLY? + YA RLY + VISIBLE "success" + NO WAI + VISIBLE "fail" + OIC +KTHXBYE diff --git a/test/1.3-Tests/5-Input/3-EscapeCharacter/test.out b/test/1.3-Tests/5-Input/3-EscapeCharacter/test.out new file mode 100644 index 0000000..7e3d094 --- /dev/null +++ b/test/1.3-Tests/5-Input/3-EscapeCharacter/test.out @@ -0,0 +1,3 @@ +:[ ] x [ ] y +: - : +success diff --git a/test/1.3-Tests/5-Input/3-EscapeCharacter/test.readme b/test/1.3-Tests/5-Input/3-EscapeCharacter/test.readme new file mode 100644 index 0000000..bcf9295 --- /dev/null +++ b/test/1.3-Tests/5-Input/3-EscapeCharacter/test.readme @@ -0,0 +1,3 @@ +This test checks that when the escape character (:) is input it is correctly +escaped. It provides two strings of text that check whether escaping occurs on +output and on comparison. diff --git a/test/1.3-Tests/5-Input/CMakeLists.txt b/test/1.3-Tests/5-Input/CMakeLists.txt index f0fb8ad..149adf6 100644 --- a/test/1.3-Tests/5-Input/CMakeLists.txt +++ b/test/1.3-Tests/5-Input/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory(1-ShortString) add_subdirectory(2-LongString) +add_subdirectory(3-EscapeCharacter)