Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested groups with duplicate keys trivially do not work, even with VDFDict #59

Open
GiovanH opened this issue Jan 9, 2024 · 1 comment

Comments

@GiovanH
Copy link

GiovanH commented Jan 9, 2024

Input file demo.vdf:

"controller_mappings"
{
	"group"
	{
		"id"		"0"
	}
	"group"
	{
		"id"		"1"
	}
}

Test script:

import vdf
with open("demo.vdf") as fp:
    v = vdf.load(fp, mapper=vdf.VDFDict)
    print(type(v))
    print(type(v['controller_mappings']))
    print(vdf.dumps(v, pretty=True))

Expected output:
(demo.vdf)

Actual output:

<class 'vdf.vdict.VDFDict'>
<class 'vdf.vdict.VDFDict'>
"controller_mappings"
{
        "group"
        {
                "id" "0"
                "id" "1"
        }
}

Not only is this incorrect, but no error is thrown: the resulting data structure is silently malformed and passed along.

@rossengeorgiev
Copy link
Contributor

Did you try setting merge_duplicate_keys=False ? The default behaviour is to merge duplicate keys.

See

vdf/vdf/__init__.py

Lines 77 to 79 in d762926

``merge_duplicate_keys`` when ``True`` will merge multiple KeyValue lists with the
same key into one instead of overwriting. You can se this to ``False`` if you are
using ``VDFDict`` and need to preserve the duplicates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants