fsprojects / FSharp.Configuration

The FSharp.Configuration project contains type providers for the configuration of .NET projects.
http://fsprojects.github.io/FSharp.Configuration/
Other
114 stars 63 forks source link

INI Question (Enhancement?): Having ; in value? #142

Closed zakaluka closed 6 years ago

zakaluka commented 6 years ago

Hello,

Is there a way to place a ; in a value such that the INI parser won't interpret it as a comment?

I have tried the following without success:

Migrations=Data Source=rmlaptop-140\sqlexpress;Initial Catalog=ZenCase
Migrations="Data Source=rmlaptop-140\sqlexpress;Initial Catalog=ZenCase"
Migrations='Data Source=rmlaptop-140\sqlexpress;Initial Catalog=ZenCase'
Migrations=Data Source=rmlaptop-140\sqlexpress\;Initial Catalog=ZenCase

There's some more variations that I also tried without success.

Finally, read the source code for the INI provider and saw that the Regex specifically prohibits ; in the value \s*(\S+)\s*=\s*([^;]*).

Would it be possible to either support quoted characters (i.e. \;) or to not treat mid-value semicolons as comments?

zakaluka commented 6 years ago

After beating my head for a couple of hours against the wall, 2 options stand out:

  1. Only treat ; as a comment if it is preceded by some sort of whitespace
  2. Don't allow comments at the end of a line (i.e. only support comments when the ; is the first character in the line)

EDIT: A third, flexible option may be to match the entire value, then use a second regex on the value to find the first occurrence of a non-quoted ; (i.e. \; is quoted, [^\\]; is not). If found, return a substring of the value value.Substring(0, match.Index + 1).

zakaluka commented 6 years ago

If there is a preference for a solution, I'm happy to submit a PR.

baronfel commented 6 years ago

https://en.wikipedia.org/wiki/INI_file#Comments Suggests to me that the comment-detection regex should look for ; only at the start of a line, and then we could remove the ; check entirely from the String matcher.

zakaluka commented 6 years ago

That's pretty much where I got my options from. I'll submit a PR with that in mind (it's a pretty minor change to the regex) and write some tests to ensure it works.

baronfel commented 6 years ago

Thank you!

zakaluka commented 6 years ago

Please note that given the following Wikipedia statement and the fact that the INI type provider currently ignores leading whitespace from a value, I have also removed trailing whitespace from the value to be consistent (and added the corresponding test).

Some implementations also ignore leading and trailing whitespace around the property value; others consider all characters following the equals sign (including whitespace) to be part of the value.

baronfel commented 6 years ago

Published as version 1.5.0