mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 18:14:25 +03:00
Fix quotes handling.
Note: considering that this feature hasn't worked, we may consider removing it entirely or partially (e.g., escaping) in order to simplify the code, as nobody has grown used to it. It seems, based on the "hex mode" mentioned in the manual page, that in the past there was no "normal" search in hex mode, and quoted strings were the only easy way to look for text. This is no longer the case nowadays. Note: the characters in the quoted string are copied out as-is to the regexp. No regexp-quoting is currently done. We may want to revisit this issue when we work on ticket #3695. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
64e6ccef7f
commit
7be9334e45
@ -43,7 +43,8 @@ typedef enum
|
|||||||
{
|
{
|
||||||
MC_SEARCH_HEX_E_OK,
|
MC_SEARCH_HEX_E_OK,
|
||||||
MC_SEARCH_HEX_E_NUM_OUT_OF_RANGE,
|
MC_SEARCH_HEX_E_NUM_OUT_OF_RANGE,
|
||||||
MC_SEARCH_HEX_E_INVALID_CHARACTER
|
MC_SEARCH_HEX_E_INVALID_CHARACTER,
|
||||||
|
MC_SEARCH_HEX_E_UNMATCHED_QUOTES
|
||||||
} mc_search_hex_parse_error_t;
|
} mc_search_hex_parse_error_t;
|
||||||
|
|
||||||
/*** file scope type declarations ****************************************************************/
|
/*** file scope type declarations ****************************************************************/
|
||||||
@ -101,21 +102,26 @@ mc_search__hex_translate_to_regex (const GString * astr, mc_search_hex_parse_err
|
|||||||
loop += ptr;
|
loop += ptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (*(tmp_str + loop) == '"')
|
else if (tmp_str[loop] == '"')
|
||||||
{
|
{
|
||||||
gsize loop2 = 0;
|
gsize loop2;
|
||||||
|
|
||||||
loop++;
|
loop2 = loop + 1;
|
||||||
while (loop + loop2 < tmp_str_len)
|
|
||||||
|
while (loop2 < tmp_str_len)
|
||||||
{
|
{
|
||||||
if (*(tmp_str + loop + loop2) == '"' &&
|
if (tmp_str[loop2] == '"')
|
||||||
!strutils_is_char_escaped (tmp_str, tmp_str + loop + loop2))
|
|
||||||
break;
|
break;
|
||||||
|
if (tmp_str[loop2] == '\\' && loop2 + 1 < tmp_str_len)
|
||||||
|
loop2++;
|
||||||
|
g_string_append_c (buff, tmp_str[loop2]);
|
||||||
loop2++;
|
loop2++;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_string_append_len (buff, tmp_str + loop, loop2 - 1);
|
if (tmp_str[loop2] == '\0')
|
||||||
loop += loop2;
|
error = MC_SEARCH_HEX_E_UNMATCHED_QUOTES;
|
||||||
|
else
|
||||||
|
loop = loop2 + 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
error = MC_SEARCH_HEX_E_INVALID_CHARACTER;
|
error = MC_SEARCH_HEX_E_INVALID_CHARACTER;
|
||||||
@ -146,7 +152,6 @@ mc_search__cond_struct_new_init_hex (const char *charset, mc_search_t * lc_mc_se
|
|||||||
mc_search_hex_parse_error_t error = MC_SEARCH_HEX_E_OK;
|
mc_search_hex_parse_error_t error = MC_SEARCH_HEX_E_OK;
|
||||||
int error_pos = 0;
|
int error_pos = 0;
|
||||||
|
|
||||||
g_string_ascii_down (mc_search_cond->str);
|
|
||||||
tmp = mc_search__hex_translate_to_regex (mc_search_cond->str, &error, &error_pos);
|
tmp = mc_search__hex_translate_to_regex (mc_search_cond->str, &error, &error_pos);
|
||||||
if (tmp != NULL)
|
if (tmp != NULL)
|
||||||
{
|
{
|
||||||
@ -168,6 +173,9 @@ mc_search__cond_struct_new_init_hex (const char *charset, mc_search_t * lc_mc_se
|
|||||||
case MC_SEARCH_HEX_E_INVALID_CHARACTER:
|
case MC_SEARCH_HEX_E_INVALID_CHARACTER:
|
||||||
desc = _("Invalid character");
|
desc = _("Invalid character");
|
||||||
break;
|
break;
|
||||||
|
case MC_SEARCH_HEX_E_UNMATCHED_QUOTES:
|
||||||
|
desc = _("Unmatched quotes character");
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
desc = "";
|
desc = "";
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,63 @@ static const struct test_hex_translate_to_regex_ds
|
|||||||
NULL,
|
NULL,
|
||||||
MC_SEARCH_HEX_E_INVALID_CHARACTER
|
MC_SEARCH_HEX_E_INVALID_CHARACTER
|
||||||
},
|
},
|
||||||
|
/*
|
||||||
|
* Quotes.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
" \"abc\" ",
|
||||||
|
"abc",
|
||||||
|
MC_SEARCH_HEX_E_OK
|
||||||
|
},
|
||||||
|
{
|
||||||
|
/* Preserve upper/lower case */
|
||||||
|
"\"aBc\"",
|
||||||
|
"aBc",
|
||||||
|
MC_SEARCH_HEX_E_OK
|
||||||
|
},
|
||||||
|
{
|
||||||
|
" 12\"abc\"34 ",
|
||||||
|
"\\x12abc\\x34",
|
||||||
|
MC_SEARCH_HEX_E_OK
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"\"a\"\"b\"",
|
||||||
|
"ab",
|
||||||
|
MC_SEARCH_HEX_E_OK
|
||||||
|
},
|
||||||
|
/* Empty quotes */
|
||||||
|
{
|
||||||
|
"\"\"",
|
||||||
|
"",
|
||||||
|
MC_SEARCH_HEX_E_OK
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"12 \"\"",
|
||||||
|
"\\x12",
|
||||||
|
MC_SEARCH_HEX_E_OK
|
||||||
|
},
|
||||||
|
/* Error: Unmatched quotes */
|
||||||
|
{
|
||||||
|
"\"a",
|
||||||
|
NULL,
|
||||||
|
MC_SEARCH_HEX_E_UNMATCHED_QUOTES
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"\"",
|
||||||
|
NULL,
|
||||||
|
MC_SEARCH_HEX_E_UNMATCHED_QUOTES
|
||||||
|
},
|
||||||
|
/* Escaped quotes */
|
||||||
|
{
|
||||||
|
"\"a\\\"b\"",
|
||||||
|
"a\"b",
|
||||||
|
MC_SEARCH_HEX_E_OK
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"\"a\\\\b\"",
|
||||||
|
"a\\b",
|
||||||
|
MC_SEARCH_HEX_E_OK
|
||||||
|
},
|
||||||
};
|
};
|
||||||
/* *INDENT-ON* */
|
/* *INDENT-ON* */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user