mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-11 05:17:44 +03:00
basic/extract_word: try to explain what the various options do
A test for stripping of escaped backslashes without any flags was explicitly
added back in 4034a06ddb
. So it seems to be on
purpose, though I would say that this is at least surprising and hence deserves
a comment.
In test-extract-word, add tests for standalone EXTRACT_UNESCAPE_SEPARATORS.
Only behaviour combined with EXTRACT_CUNESCAPE was tested.
This commit is contained in:
parent
5fa2da1251
commit
8723c716c7
@ -4,13 +4,15 @@
|
||||
#include "macro.h"
|
||||
|
||||
typedef enum ExtractFlags {
|
||||
EXTRACT_RELAX = 1 << 0,
|
||||
EXTRACT_CUNESCAPE = 1 << 1,
|
||||
EXTRACT_CUNESCAPE_RELAX = 1 << 2,
|
||||
EXTRACT_UNESCAPE_SEPARATORS = 1 << 3,
|
||||
EXTRACT_UNQUOTE = 1 << 4,
|
||||
EXTRACT_DONT_COALESCE_SEPARATORS = 1 << 5,
|
||||
EXTRACT_RETAIN_ESCAPE = 1 << 6,
|
||||
EXTRACT_RELAX = 1 << 0, /* Allow unbalanced quote and eat up trailing backslash. */
|
||||
EXTRACT_CUNESCAPE = 1 << 1, /* Unescape known escape sequences. */
|
||||
EXTRACT_CUNESCAPE_RELAX = 1 << 2, /* Allow and keep unknown escape sequences, allow and keep trailing backslash. */
|
||||
EXTRACT_UNESCAPE_SEPARATORS = 1 << 3, /* Unescape separators (those specified, or whitespace by default). */
|
||||
EXTRACT_UNQUOTE = 1 << 4, /* Remove quoting with "" and ''. */
|
||||
EXTRACT_DONT_COALESCE_SEPARATORS = 1 << 5, /* Don't treat multiple adjacent separators as one */
|
||||
EXTRACT_RETAIN_ESCAPE = 1 << 6, /* Treat escape character '\' as any other character without special meaning */
|
||||
|
||||
/* Note that if no flags are specified, escaped escape characters will be silently stripped. */
|
||||
} ExtractFlags;
|
||||
|
||||
int extract_first_word(const char **p, char **ret, const char *separators, ExtractFlags flags);
|
||||
|
@ -344,6 +344,27 @@ static void test_extract_first_word(void) {
|
||||
free(t);
|
||||
assert_se(p == NULL);
|
||||
|
||||
p = "\\:";
|
||||
assert_se(extract_first_word(&p, &t, ":", EXTRACT_UNESCAPE_SEPARATORS) == 1);
|
||||
assert_se(streq(t, ":"));
|
||||
free(t);
|
||||
assert_se(p == NULL);
|
||||
|
||||
p = "a\\:b";
|
||||
assert_se(extract_first_word(&p, &t, ":", EXTRACT_UNESCAPE_SEPARATORS) == 1);
|
||||
assert_se(streq(t, "a:b"));
|
||||
free(t);
|
||||
assert_se(p == NULL);
|
||||
|
||||
p = "a\\ b:c";
|
||||
assert_se(extract_first_word(&p, &t, WHITESPACE ":", EXTRACT_UNESCAPE_SEPARATORS) == 1);
|
||||
assert_se(streq(t, "a b"));
|
||||
free(t);
|
||||
assert_se(extract_first_word(&p, &t, WHITESPACE ":", EXTRACT_UNESCAPE_SEPARATORS) == 1);
|
||||
assert_se(streq(t, "c"));
|
||||
free(t);
|
||||
assert_se(p == NULL);
|
||||
|
||||
p = "\\:";
|
||||
assert_se(extract_first_word(&p, &t, ":", EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS) == 1);
|
||||
assert_se(streq(t, ":"));
|
||||
|
Loading…
Reference in New Issue
Block a user