Tk Library Source Code

View Ticket
Login
Ticket UUID: 2593520
Title: json one-line fix for number parsing
Type: Patch Version: None
Submitter: zvr Created on: 2009-02-12 17:26:18
Subsystem: json Assigned To: hobbs
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2009-04-25 04:35:55
Resolution: Fixed Closed By: hobbs
    Closed on: 2009-04-24 21:35:55
Description:
in json::_json2dict, when parsing a number value
(line 192ff.), the code essentially does:
string is double -failindex last $txt
set num [string range $txt 0 [expr {$last - 1}]]

WHAT: this code works fine for cases like
attr: 123,
but not for cases with whitespace after the number,
e.g. if it's the last attribute of an object
attr: 123
        }

WHY: due to "last" being set to failindex
(the character that fails the "is double" test),
the resulting "num" also contains all whitespace
after the number and before the failing char.

FIX: add a "string trimright" to the num definition.
User Comments: hobbs added on 2009-04-25 04:35:55:

allow_comments - 1

kanryu6 applied this patch on 2009/04/17:

@@ -194,7 +194,7 @@
            # but it may be 0.xxx
            string is double -failindex last $txt
            if {$last > 0} {
-               set num [string range $txt 0 [expr {$last - 1}]]
+        regexp -- {-?[\d\.]+([eE][\+-]?\d+)?} $txt num
                set txt [string range $txt $last end]

                switch -- $state {

kanryu6 added on 2009-04-18 06:34:41:
fixed at CVS HEAD