Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.8.1
-
None
-
None
Description
When a ConfigObject is written to file all values are quoted with ". This leads to problems if a value contains a $ for example.
Consider the following code snipet:
def config = new ConfigObject() config.instObject = '1. Dyn. Aktber. ($IO_AKTBER) # Aktenbereich (V-AKTBER)' println "config before writing to file: ${config}" def file = new File('C:/Temp/config.groovy') file.withWriter { writer -> config.writeTo(writer) } config = new ConfigSlurper().parse(file.getText()) println "config after reloading from file: ${config}"
The output is:
config before writing to file: [instObject:1. Dyn. Aktber. ($IO_AKTBER) # Aktenbereich (V-AKTBER)] config after reloading from file: [IO_AKTBER:[:], instObject:1. Dyn. Aktber. ([:]) # Aktenbereich (V-AKTBER)]
The according file content:
instObject="1. Dyn. Aktber. ($IO_AKTBER) # Aktenbereich (V-AKTBER)"
As can be seen the two config objects differ widely. A solution could perhaps be writing properties quoted by ' or writing the properties the way they are quoted in the source code, e. g. config.property1 = "$property1" would become property1 = "$property1" in the file and config.property2 = '$property1' would become property2 = '$property1'. This way the programmer could control the desired behaviour.