Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-4958

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.8.1
    • 1.8.5, 2.0-beta-2
    • 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.

      Attachments

        1. GROOVY-4958_Patch.diff
          5 kB
          Roshan Dawrani

        Activity

          People

            roshandawrani Roshan Dawrani
            erpl Erich Paul
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: