Status/Resolution/Reason: Closed/Fixed/Fixed
Reporter/Name(from Bugbase): Ben F. / ()
Created: 03/08/2019
Components: Language, Validation
Versions: 2016,11.0,2018
Failure Type: Incorrectly functioning
Found In Build/Fixed In Build: CF Engine: adobe 10.0.23+302580 / CF2016U12,CF2018U5
Priority/Frequency: Normal / Most users will encounter
Locale/System: ALL / Windows 10 64 bit
Vote Count: 3
Problem Description:
The isJSON function returns sometimes true for a given string, that is not correct JSON. If you use isJSON to check for a JSON string and then try to parse that you get unexpected errors.
Steps to Reproduce:
Run the following code:
var a = "-";
if (isJSON(a)) {
var b = deserializeJSON(a); // <====== throws an error! a is not correct JSON
}
I have created a cffiddle to demonstrate the problem. The red line are where CF incorrectly says that the value is a valid JSON, when it is really not valid.
https://cffiddle.org/app/file?filepath=c9e6c812-729e-487d-ad73-b1a95b05f64c/063797c5-96cf-4d1b-8604-594d6237f350/6d2d3c24-c6ad-48bc-8713-a7c0406e0123.cfm
I have validated all the sample values with https://jsonlint.com/ and double checked with the JSON definition at:https://www.json.org/
Workaround:
Always use deserialiseJSON instead of isJSON and put a try/catch around the deserializeJSON() function.
Attachments:
Comments: