Tk Library Source Code

View Ticket
Login
Ticket UUID: 3612465
Title: Spaces around section line specifications should be ignored
Type: Bug Version: None
Submitter: takatsuki Created on: 2013-05-02 09:14:22
Subsystem: inifile Assigned To: aku
Priority: 5 Medium Severity: Minor
Status: Deleted Last Modified: 2013-05-31 19:18:06
Resolution: Not Applicable Here Closed By: aku
    Closed on: 2013-05-31 19:18:06
Description:
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
User Comments: ferrieux added on 2013-05-02 23:28:26:
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...

ferrieux added on 2013-05-02 23:24:56:
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.tcl2013-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] } {

takatsuki added on 2013-05-02 16:14:23:

File Added - 463065: inifile-sections.patch

Attachments: