From 51dc3763bb0e9505695d49ba549189e505e2d806 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 5 Mar 2023 22:29:17 -0600 Subject: [PATCH] Bugfix: Fix unterminated quote handling issue addressed by specifications clarification. These commits clarified the specification: - e79fd90eb383acd5cdcb03f20d5fd2661a423c7c - 4f2a4866eddceac491da0e02d868916316e32c9c This clarification paved the way for a solution to the bug where lines with unterminated quotes are not getting anything at all. By "favoring the typo", the rest of the line is preserved and is able to be printed. --- level_1/fl_fss/c/fss/basic.c | 5 +++++ level_1/fl_fss/c/fss/extended.c | 12 +++++++++++- level_1/fl_fss/c/private-fss.c | 13 ++++++++++++- level_1/fl_fss/c/private-fss.h | 1 + 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/level_1/fl_fss/c/fss/basic.c b/level_1/fl_fss/c/fss/basic.c index 23493a1..0d58345 100644 --- a/level_1/fl_fss/c/fss/basic.c +++ b/level_1/fl_fss/c/fss/basic.c @@ -147,6 +147,11 @@ extern "C" { const f_status_t status = private_fl_fss_basic_read(buffer, F_true, state, range, found, quote, delimits); + // The private function sets the error bit on unterminated quoted Object. + if (status == F_status_set_error(F_fss_found_object_content_not)) { + return F_fss_found_object_content_not; + } + if (F_status_is_error(status) || status == F_fss_found_object_not || status == F_data_not || status == F_data_not_eos || status == F_data_not_stop) { delimits->used = delimits_used; } diff --git a/level_1/fl_fss/c/fss/extended.c b/level_1/fl_fss/c/fss/extended.c index 09d53b8..81193e7 100644 --- a/level_1/fl_fss/c/fss/extended.c +++ b/level_1/fl_fss/c/fss/extended.c @@ -43,13 +43,18 @@ extern "C" { status = private_fl_fss_basic_read(buffer, F_false, state, range, &content_partial, "e, delimits); - if (status == F_fss_found_object || status == F_fss_found_object_content_not) { + if (status == F_fss_found_object || F_status_set_fine(status) == F_fss_found_object_content_not) { status_allocate = f_string_ranges_increase(state.step_small, found); if (F_status_is_error_not(status_allocate) && quotes) { status_allocate = f_uint8s_increase(state.step_small, quotes); } + // The private function sets the error bit on unterminated quoted Object. + if (status == F_status_set_error(F_fss_found_object_content_not)) { + status = F_fss_found_object_content_not; + } + if (F_status_is_error(status_allocate)) { delimits->used = delimits_used; @@ -198,6 +203,11 @@ extern "C" { const f_status_t status = private_fl_fss_basic_read(buffer, F_true, state, range, found, quote, delimits); + // The private function sets the error bit on unterminated quoted Object. + if (status == F_status_set_error(F_fss_found_object_content_not)) { + return F_fss_found_object_content_not; + } + if (F_status_is_error(status) || status == F_fss_found_object_not || status == F_data_not || status == F_data_not_eos || status == F_data_not_stop) { delimits->used = delimits_used; } diff --git a/level_1/fl_fss/c/private-fss.c b/level_1/fl_fss/c/private-fss.c index 0775d47..c2dd489 100644 --- a/level_1/fl_fss/c/private-fss.c +++ b/level_1/fl_fss/c/private-fss.c @@ -140,6 +140,9 @@ extern "C" { if (status == F_none_stop) return F_data_not_stop; if (status == F_data_not) return status; + // Save the delimits used position in case of unterminated quote. + const f_array_length_t delimits_used = delimits->used; + // Begin the search. found->start = range->start; @@ -619,10 +622,18 @@ extern "C" { } else if (buffer.string[range->start] == f_fss_eol_s.string[0]) { + // The quote is incomplete, so treat the entire line as the Object as per the specification (including the quotes). + // The error bit is set to designate that the Object is found in an erroneous state (not having a terminating quote). + found->start -= 1; + found->stop = range->start - 1; + + // The delimits cannot be preserved in this case as per specification. + delimits->used = delimits_used; + // Move the start position to after the EOL. ++range->start; - return F_fss_found_object_not; + return F_status_set_error(F_fss_found_object_content_not); } status = f_utf_buffer_increment(buffer, range, 1); diff --git a/level_1/fl_fss/c/private-fss.h b/level_1/fl_fss/c/private-fss.h index ae3b4ef..d3747aa 100644 --- a/level_1/fl_fss/c/private-fss.h +++ b/level_1/fl_fss/c/private-fss.h @@ -128,6 +128,7 @@ extern "C" { * F_end_not_group_eos if EOS was reached before the a group termination was reached. * F_end_not_group_stop if stop point was reached before the a group termination was reached. * + * F_fss_found_object_content_not (with error bit) If an unterminated quoted Object is found. * F_interrupt (with error bit) if stopping due to an interrupt. * F_none_eol (with error bit) after reaching an EOL, which is not supported by the standard. * F_parameter (with error bit) if a parameter is invalid. -- 1.8.3.1