paradigmatic / Configrity

Simple, immutable and flexible configuration library for scala.
Other
132 stars 19 forks source link

Bug when parsing files with whatespaces in path #12

Closed tomasherman closed 12 years ago

tomasherman commented 12 years ago

Hey there, Configrity seems to be throwing exceptions when parsing Files that contain whitespaces in the path. Is this a bug?

example of configuration:

managed {
  directories = [C:\Users\arg\Documents\RCT3,C:\Users\arg\Documents\StarCraft II\Accounts\662168\2-S2-1-821040\Replays\Multiplayer]
}

I should mention that the configuration file is generated by the library itself.

we have here a list of files, this error is thrown:

org.streum.configrity.io.StandardFormat$ParserException: [2.79] failure: `]' expected but `I' found

  directories = [C:\Users\arg\Documents\RCT3,C:\Users\arg\Documents\StarCraft II\Accounts\662168\2-S2-1-821040\Replays\Multiplayer]
paradigmatic commented 12 years ago

As stated in the wiki, Strings must be enclosed in double-quotes if they contain whitespace.

But if the value is generated by the library without quotes, it looks like a bug. I will try to fix it this week-end. Could you please show me how do you set the directories value in your code ?

tomasherman commented 12 years ago

Sure, this is the code:

  private class Content extends BoxPanel(Orientation.Vertical) {
    val panel = this
    contents += new Button("Add folder") {
      listenTo(this)
      reactions += {
        case ButtonClicked(b) if b == this => {
          val f = new FileChooser()
          f.fileSelectionMode = FileChooser.SelectionMode.DirectoriesOnly
          f.showDialog(panel, "Choose") match {
            case FileChooser.Result.Approve => {
              list.listData = list.listData :+ f.selectedFile
            }
            case _ =>
          }
        }
      }
    }
    contents += new ScrollPane(list)
    contents += new BoxPanel(Orientation.Horizontal) {
      contents += new SelfButton("Save", { () =>
        configActor ! UpdateConfig(cfg.set(ConfigKeys.directories, list.listData.toSet.toList))
        dialog.dispose                                          
      })
      contents += new SelfButton("Exit", { dialog.dispose })
    }  
  }

I use swing ListView to display the directories and when user adds some, i simply add it to the configuration and bang it to another actor.

To persist the configuration, i use:

 outputFile.outputStream(WriteTruncate:_*).write(config.format()) 

(i use scalax io library)

tomasherman commented 12 years ago

I was looking into the code base, if i understand it correctly,

      def set[A]( key: String, a: A ) =
         Configuration( data + ( key -> a.toString ) )

shouldn't add " " around the a if the a is a string (or file, for that matter)?

paradigmatic commented 12 years ago

We should add quotes only when needed (when the list values contain spaces or other non alphanumeric characters).

paradigmatic commented 12 years ago

As long as I can check, the issue is fixed on the master branch. I've added two tests to check the issue. Could you please test it ? I will try to generate and publish the artifacts tonight.

tomasherman commented 12 years ago

I will test it when the artifact is released, if that's ok. Also, thanks a lot for fast fix :)

On Sun, May 6, 2012 at 1:14 PM, Paradigmatic < reply@reply.github.com

wrote:

As long as I can check, the issue is fixed on the master branch. I've added two tests to check the issue. Could you please test it ? I will try to generate and publish the artifacts tonight.


Reply to this email directly or view it on GitHub: https://github.com/paradigmatic/Configrity/issues/12#issuecomment-5534867

tomasherman commented 12 years ago

Hey, just wanted to say that it indeed fixed my issue. Once again, thanks

paradigmatic commented 12 years ago

Glad to help and thanks for reporting the issue.