config icon indicating copy to clipboard operation
config copied to clipboard

parseMap can't handle keys with special characters

Open hallyhaa opened this issue 5 years ago • 2 comments

In the following code, I never reach the final line:

        // quoted key containing an '@' is alright:
        Config config = ConfigFactory.parseString("\"hah@a\": hehe");
        System.out.println("config.root().render(): " + config.root().render());

        // Config's rendering function quotes keys and values OK:
        Config reConfig = ConfigFactory.parseString(config.root().render());
        System.out.println("reConfig.root().render(): " + reConfig.root().render());

        // Converting to a map is OK:
        Map<String, ?> map = config.root().unwrapped();
        System.out.println("map: " + map);

        // But recapturing as a config from that very same map isn't:
        Config reReConfig = ConfigFactory.parseMap(map);
        System.out.println("reReConfig.root().render():" + reReConfig.root().render());

The parseMap method throws a ConfigException$BadPath. Is this really meant to be so?

hallyhaa avatar Feb 21 '20 16:02 hallyhaa

By calling root() you get the types mixed up; you’re creating a map that’s a json-like tree data structure with syntaxless string keys, and passing it to parseMap which expects a 1-level flat data structure with paths as keys.

havocp avatar Feb 21 '20 16:02 havocp

You mean by calling unwrapped()? It does indeed not crash when I drop the call to unwrapped(). Thanks.

hallyhaa avatar Feb 24 '20 11:02 hallyhaa