tracker issue : CF-4204079

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

isJSON gives false positives

| View in Tracker

Status/Resolution/Reason: To Test//Fixed

Reporter/Name(from Bugbase): Ben F. / ()

Created: 03/08/2019

Components: Validation

Versions: 2016,11.0,2018

Failure Type: Incorrectly functioning

Found In Build/Fixed In Build: CF Engine: adobe 10.0.23+302580 /

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:

+1
Vote by A. B.
30454 | March 08, 2019 02:21:15 PM GMT
Great find, Ben!
Comment by A. B.
30453 | March 08, 2019 02:22:52 PM GMT
To clarify, I found this bug in CF10, CF11, CF2016 and CF2018
Comment by Ben F.
30512 | March 15, 2019 06:56:39 AM GMT