rickyah / ini-parser

Read/Write an INI file the easy way!
MIT License
971 stars 241 forks source link

Multiple sections throwing error #172

Open vreguibar opened 6 years ago

vreguibar commented 6 years ago

Hi,

I have an ini file which has several sections. Everything goes OK until one of the sections has a different Key pair:

Example OK: [My Registry] MACHINE\Software\EguibarIT\SecurityMode=1,"1"

Example with error [My Registry] MACHINE\Software\EguibarIT\SecurityMode=1,"1"

[My Other Registry] "MACHINE\SOFTWARE\EguibarIT\AccountPicture\ID",0,"D:PAR(A;CI;KR;;;S-1-15-2-1)(A;CIIO;KA;;;CO)(A;CI;KA;;;SY)(A;CI;KA;;;BA)(A;CI;KA;;;BU)"

I understand that the = sign is used to build the Key=Value pair, but in my example above the "",number,"" is defining it.

If setting this to SkipInvalidLines then the whole line gets deleted.

I try using RegEx as Regex("(\".?\")\,[0-9]\,(\".?\")") but then the "MACHINE gets changed to #Machine, which breakes my application.

Is there any configuration I'm missing?

Thanks in advance Regards Vicente

rickyah commented 6 years ago

Will look into it, thanks for reporting

rickyah commented 6 years ago

Ok, problem seems that the ; is being used a the comment character. so your second string is actually processed like this: "MACHINE\SOFTWARE\EguibarIT\AccountPicture\ID",0,"D:PAR(A The rest is discarded and considered a comment As that string does not contains an equal sign, it is neither a section nor a property, so the parser fails.

A solution would be to set parser.Configuration.CommentString = "#"; (or any other symbol not used on the file) before parsing.

Let me know if that worked