Skip to content

Commit

Permalink
Bugfix: A lone quote inside quotes should not be escaped for FSS Basi…
Browse files Browse the repository at this point in the history
…c and Extended.

The command and results:
  # fss_extended_write -oc "'" '"' -oc '"' "'" -oc ' `' "\` " -oc "'" "'" | fss_extended_read -oc
  ' \"
  \" '
  ` `
  ' '

Is incorrect.
The correct results should be:
  # fss_extended_write -oc "'" '"' -oc '"' "'" -oc ' `' "\` " -oc "'" "'" | fss_extended_read -oc
  ' "
  " '
  ` `
  ' '

The problem is that in the case where the quote is already within a quoted string then it should not be escaped.
This only applies for the quote that would not be a valid closing quote.
  • Loading branch information
thekevinday committed May 23, 2024
1 parent 8e4d0ec commit f180e1c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions level_1/fl_fss/c/private-fss.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,19 +972,25 @@ extern "C" {
else if (object.string[range->start] == quote_char) {
item_first = range->start++;

// The very first quote, must be escaped, when quoting is disabled.
status = f_fss_skip_past_delimit(state, object, range);
if (F_status_is_error(status)) return status;

// The very first quote, must be escaped, but only when quoting is disabled or first quote is followed by white space.
if (item_first == input_start) {
status = f_string_dynamic_increase(state.step_large, destination);
if (F_status_is_error(status)) break;
if (quote_is) {
status = f_fss_is_space(state, object, *range);
if (F_status_is_error(status)) break;
}

destination->string[used_start + 1] = f_fss_delimit_slash_s.string[0];
}
if (!quote_is || quote_is && status == F_true) {
status = f_string_dynamic_increase(state.step_large, destination);
if (F_status_is_error(status)) break;

status = f_fss_skip_past_delimit(state, object, range);
if (F_status_is_error(status)) return status;
destination->string[used_start + 1] = f_fss_delimit_slash_s.string[0];
}
}

if (range->start > range->stop || range->start >= object.used) {

status = f_string_dynamic_increase(state.step_large, destination);
if (F_status_is_error(status)) break;

Expand Down

0 comments on commit f180e1c

Please sign in to comment.