mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-29 15:22:30 +03:00
libdm-config: Allow quoted section (and key) names.
This commit is contained in:
parent
2e82a070f3
commit
c353949597
@ -287,6 +287,7 @@ static int _write_config(const struct dm_config_node *n, int only_one,
|
|||||||
char space[MAX_INDENT + 1];
|
char space[MAX_INDENT + 1];
|
||||||
int l = (level < MAX_INDENT) ? level : MAX_INDENT;
|
int l = (level < MAX_INDENT) ? level : MAX_INDENT;
|
||||||
int i;
|
int i;
|
||||||
|
char *escaped_key = NULL;
|
||||||
|
|
||||||
if (!n)
|
if (!n)
|
||||||
return 1;
|
return 1;
|
||||||
@ -301,7 +302,14 @@ static int _write_config(const struct dm_config_node *n, int only_one,
|
|||||||
|
|
||||||
if (!_line_start(out))
|
if (!_line_start(out))
|
||||||
return_0;
|
return_0;
|
||||||
line_append("%s%s", space, n->key);
|
if (strchr(n->key, '#') || strchr(n->key, '"') || strchr(n->key, '!')) {
|
||||||
|
escaped_key = alloca(dm_escaped_len(n->key) + 2);
|
||||||
|
*escaped_key = '"';
|
||||||
|
dm_escape_double_quotes(escaped_key + 1, n->key);
|
||||||
|
strcat(escaped_key, "\"");
|
||||||
|
}
|
||||||
|
line_append("%s%s", space, escaped_key ? escaped_key : n->key);
|
||||||
|
escaped_key = NULL;
|
||||||
if (!n->v) {
|
if (!n->v) {
|
||||||
/* it's a sub section */
|
/* it's a sub section */
|
||||||
line_append(" {");
|
line_append(" {");
|
||||||
@ -433,15 +441,23 @@ static struct dm_config_node *_section(struct parser *p)
|
|||||||
{
|
{
|
||||||
/* IDENTIFIER SECTION_B_CHAR VALUE* SECTION_E_CHAR */
|
/* IDENTIFIER SECTION_B_CHAR VALUE* SECTION_E_CHAR */
|
||||||
struct dm_config_node *root, *n, *l = NULL;
|
struct dm_config_node *root, *n, *l = NULL;
|
||||||
|
char *token;
|
||||||
if (!(root = _create_node(p->mem))) {
|
if (!(root = _create_node(p->mem))) {
|
||||||
log_error("Failed to allocate section node");
|
log_error("Failed to allocate section node");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(root->key = _dup_tok(p)))
|
if (!(root->key = token = _dup_tok(p)))
|
||||||
return_NULL;
|
return_NULL;
|
||||||
|
|
||||||
match(TOK_IDENTIFIER);
|
if (p->t == TOK_STRING_ESCAPED) {
|
||||||
|
token ++; /* OK as the token is pool-allocated */
|
||||||
|
token[strlen(token) - 1] = 0;
|
||||||
|
dm_unescape_double_quotes(token);
|
||||||
|
root->key = token;
|
||||||
|
match(TOK_STRING_ESCAPED);
|
||||||
|
} else
|
||||||
|
match(TOK_IDENTIFIER);
|
||||||
|
|
||||||
if (p->t == TOK_SECTION_B) {
|
if (p->t == TOK_SECTION_B) {
|
||||||
match(TOK_SECTION_B);
|
match(TOK_SECTION_B);
|
||||||
|
Loading…
Reference in New Issue
Block a user