groovy
  1. groovy
  2. GROOVY-4958

ConfigSlurper doesn't parse config files that contain $ signs in property values correctly

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.8.1
    • Fix Version/s: 1.8.5, 2.0-beta-2
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      1

      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.

        Activity

          People

          • Assignee:
            Roshan Dawrani
            Reporter:
            Erich Paul
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: