From 5dd1e6a1cd8b3c6c8a8f4d241cd39c5317a34218 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 15 Nov 2020 17:36:55 -0600 Subject: [PATCH] Bugfix: Embedded List is not properly handling delimits on write. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This is hard to observe because of how bash handles newlines. For example: echo "$(echo -e " To {\n World\n \\\\\\\\\\\\\\{\n")" Would produce a string where the slashes after world actually represent a total of 4 slashes. The problem with bash is that it "guesses" the number of slashes. Another concern is that there are two quotes, so a slash has to be escaped twice for such a string in bash. As a more complex example, see: # echo "$(echo -e "\\\\\\\\\\\\\\")" | byte_dump -tcw 5 Piped Byte Dump: (in Hexidecimal) 0000000000000000 5c 5c 5c 5c 0a | \\\\␤ | # echo "$(echo -e "\\\\\\\\\\")" | byte_dump -tcw 5 Piped Byte Dump: (in Hexidecimal) 0000000000000000 5c 5c 5c 0a | \\\␤ | Once past the confusing behavior of backslash escaping in Bash, one can then observe that this project is incorrectly escaping backslashes. In the case of Embedded List close character (the close brace '}') only the first backslash needs to be escaped. In the case of Embedded List open character (the open brace '{') every even backslash must be escaped (and there should only be a single unescaped odd backslash). The problem is that the code is treating the close brace as an open brace, resulting in too many backslashes. There is also an ends of EOL boolean that appears to be being incorrectly set. The EOL is detected at range->start position, but the position is being reset to the saved "start" position. --- level_1/fl_fss/c/fss_embedded_list.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/level_1/fl_fss/c/fss_embedded_list.c b/level_1/fl_fss/c/fss_embedded_list.c index 51b629c..24d2107 100644 --- a/level_1/fl_fss/c/fss_embedded_list.c +++ b/level_1/fl_fss/c/fss_embedded_list.c @@ -1111,20 +1111,15 @@ extern "C" { } else if (content.string[range->start] == f_fss_eol || range->start >= content.used || range->start > range->stop) { - if (content.string[range->start] == f_fss_eol) { - ends_on_eol = F_true; - } - else { - ends_on_eol = F_false; - } - - // increase by total slashes + 1, along with the extended list open and possible newline. - status = private_fl_fss_destination_increase_by(slash_count + 3, destination); + // increase by total slashes + 1 embedded list open/close. + status = private_fl_fss_destination_increase_by(slash_count + 2, destination); if (F_status_is_error(status)) break; - while (slash_count--) { - destination->string[destination->used++] = f_fss_delimit_slash; - } // while + if (content.string[range->start] == f_fss_embedded_list_open) { + while (slash_count--) { + destination->string[destination->used++] = f_fss_delimit_slash; + } // while + } destination->string[destination->used++] = f_fss_delimit_slash; destination->string[destination->used++] = content.string[start]; -- 1.8.3.1