1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-07-22 05:21:51 +03:00

tests: Unit test nested quotes

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 7f045e2d91)
This commit is contained in:
Jakub Jelen
2025-02-11 12:35:46 +01:00
parent 3daa06dba7
commit 5911d058f1

View File

@ -2104,6 +2104,7 @@ static void torture_config_parser_get_cmd(void **state)
* * Strip leading whitespace
* * Return first token separated by whitespace or equal sign,
* respecting quotes!
* * Correctly treat escaped quotes inside of quotes.
*/
static void torture_config_parser_get_token(void **state)
{
@ -2276,6 +2277,28 @@ static void torture_config_parser_get_token(void **state)
tok = ssh_config_get_token(&p);
assert_string_equal(tok, "value");
assert_int_equal(*p, '\0');
/* Escaped quotes */
strncpy(data, " \"value with \\\"escaped\\\" quotes\" \n", sizeof(data));
p = data;
tok = ssh_config_get_token(&p);
assert_string_equal(tok, "value with \"escaped\" quotes");
assert_int_equal(*p, '\0');
strncpy(data, "\\\"value with \\\"escaped\\\" quotes\\\"\n", sizeof(data));
p = data;
tok = ssh_config_get_token(&p);
assert_string_equal(tok, "\\\"value");
assert_int_equal(*p, 'w');
tok = ssh_config_get_token(&p);
assert_string_equal(tok, "with");
assert_int_equal(*p, '\\');
tok = ssh_config_get_token(&p);
assert_string_equal(tok, "\\\"escaped\\\"");
assert_int_equal(*p, 'q');
tok = ssh_config_get_token(&p);
assert_string_equal(tok, "quotes\\\"");
assert_int_equal(*p, '\0');
}
/* match_pattern() sanity tests