tracker issue : CF-4206421

select a category, or use search below
(searches all categories and all time range)
Title:

ColdFusion JSON Serialization produces invalid output from string representations of negative decimal numbers

| View in Tracker

Status/Resolution/Reason: To Fix//

Reporter/Name(from Bugbase): Kevin D. / ()

Created: 12/18/2019

Components: Language, Serialization

Versions: 2016

Failure Type: Incorrectly functioning

Found In Build/Fixed In Build: 2016,0,11,314546 /

Priority/Frequency: Normal / Few users will encounter

Locale/System: English / Linux

Vote Count: 0

Problem Description: ColdFusion SerializeJSON returns invalid JSON when presented with certain values. This also occurs when remote component functions are called specifying returnformat="JSON".

A string that contains a negative decimal number without a leading zero (e.g. -.03) is converted into a bare number also missing the leading zero, which is invalid per the ECMA-404 standard.

Steps to Reproduce: 
Case A: Serialize a string like "-.03". Call this function from a browser or any other sort of AJAX source, for example:
component {
    remote string function caseA () {
        return SerializeJSON({name: "-.03"});
    }
}

Case B: Return a string like "-.03" from a remote function, specifying returnformat="JSON". Example:
component {
    remote struct function caseB () returnformat="JSON" {
        return name: "-.03"};
    }
}


Actual Result: The string representation of the negative decimal is incorrectly converted into a number. Both case A and B return the same:
{"NAME":-.03}

Expected Result: Correct conversion would look like this:
{"NAME":-0.03}

Alternatively, it could return the value as a string, although I do not believe that is default behavior for ColdFusion's type conversion:
{"NAME":"-.03"}

Any Workarounds: I have not tested it yet, but I believe I can be explicit with JSON serialization instructions to force the values to be returned as strings.

Attachments:

Comments: