Closed zakaluka closed 6 years ago
After beating my head for a couple of hours against the wall, 2 options stand out:
;
as a comment if it is preceded by some sort of whitespace;
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)
.
If there is a preference for a solution, I'm happy to submit a PR.
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.
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.
Thank you!
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.
Published as version 1.5.0
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:
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?