lightbend / config

configuration library for JVM languages using HOCON files
https://lightbend.github.io/config/
6.14k stars 967 forks source link

parseMap can't handle keys with special characters #670

Open hallyhaa opened 4 years ago

hallyhaa commented 4 years ago

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?

havocp commented 4 years ago

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.

hallyhaa commented 4 years ago

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