diff --git a/list.c b/list.c index 304c9e1..d6bd0bc 100644 --- a/list.c +++ b/list.c @@ -730,6 +730,7 @@ int uci_set(struct uci_context *ctx, struct uci_ptr *ptr) } else { struct uci_section *old = ptr->s; ptr->s = uci_alloc_section(ptr->p, ptr->value, old->e.name, &old->e.list); + ptr->s->anonymous = old->anonymous; uci_section_transfer_options(ptr->s, old); if (ptr->section == old->e.name) ptr->section = ptr->s->e.name; diff --git a/tests/shunit2/tests.d/030_set b/tests/shunit2/tests.d/030_set index db3c259..4aadda3 100644 --- a/tests/shunit2/tests.d/030_set +++ b/tests/shunit2/tests.d/030_set @@ -44,3 +44,19 @@ test_set_existing_option_multiline() World\"" assertSameFile ${REF_DIR}/set_existing_option_multiline.result ${CHANGES_DIR}/set } + +test_set_anonymous_section_type_preserves_anonymous() +{ + cat > ${CONFIG_DIR}/set << 'EOF_CONFIG' +config short + option value 'kept' +EOF_CONFIG + + ${UCI} set 'set.@short[0]=longer' + ${UCI} commit set + + output=$(${UCI} export set) + echo "$output" | grep -q '^config longer$' + assertTrue "changing an anonymous section type makes it named" $? + assertEquals "kept" "$(${UCI} get 'set.@longer[0].value')" +}