tracker issue : CF-4204079

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

isJSON gives false positives

| View in Tracker

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.

I have validated all the sample values with and double checked with the JSON definition at:

Always use deserialiseJSON instead of isJSON and put a try/catch around the deserializeJSON() function.



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