#1365 Spaces around section line specifications should be ignored

open
inifile (13)
5
2014-08-18
2013-05-02
No

When parsing a file, if a section line contains some leading or trailing spaces (outside the square brackets), it is not recognized. A sample ini file reproducing the error would be (please note the extra trailing in the section line: "[General] "):

[General]
key=value
key2=value2

# Before patch
package require inifile
set fh [::ini::open sample.ini]
puts [llength [ini::sections $fh]]
0

# After applying the attached patch
package require inifile
set fh [::ini::open sample.ini]
puts [llength [ini::sections $fh]]
1

Discussion

  • ryotakatsuki

    ryotakatsuki - 2013-05-02

    Ignore leading and trailing spaces in sections

     
  • Alexandre Ferrieux

    Why stop halfway ? Comments and settings line would benefit from the same tolerance.
    The simpler patch below does that.

    --- ini.tcl~ 2013-05-02 18:24:50.000000000 +0200
    +++ ini.tcl 2013-05-02 18:25:24.000000000 +0200
    @@ -113,6 +113,7 @@
    seek $channel 0 start

    foreach line [split [read $channel] "\n"] {
    + set line [string trim $line]
    if { [string match "$char*" $line] } {
    lappend com [string trim [string range $line [string length $char] end]]
    } elseif { [string match {\[*\]} $line] } {

     
  • Alexandre Ferrieux

    For the record, I know how Stupid SF eats any indentation, which makes any inlined patch nearly unusable, but the same Stupid SF won't allow me to attach anything...

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks