tracker issue : CF-3689989

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

serializeJson not cleaning most of the first 31 characters in the ASCII table.

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/

Reporter/Name(from Bugbase): Pat Moody / Pat Moody (Pat Moody)

Created: 01/07/2014

Components: AJAX, Plumbing

Versions: 10.0

Failure Type:

Found In Build/Fixed In Build: Final /

Priority/Frequency: Major / All users will encounter

Locale/System: English / Windows 7 64-bit

Vote Count: 3

Problem Description: Invalid JSON data is being created from data extacted from MSSQL tables. chr(1) to chr(7) + chr(11) + chr(14) to chr(31) - Possibly others?? 

Steps to Reproduce:
See attachment
test_json.cfm
<!--- chr(1) to chr(7) + chr(11) + chr(14) to chr(31) --->
<cfset char_val = chr(1) >

<cfset tblTemp = queryNew("character", "VarChar") >

<cfset QueryAddRow(tblTemp) >
<cfset querySetCell(tblTemp, "character", "ascii character after here.. " , 1) >

<cfquery dbtype="query" name="ascii_data" >		
	select [character] + '#char_val#'  +  ' End' as [character]
	from tblTemp
</cfquery>

<cfset jsonData = serializeJSON(ascii_data) >

<cfcontent type="text/html; charset=utf-8" />

<cfoutput>

	<!doctype html>
	<html>
	<head>
		<meta charset="utf-8" />

		<title>
			JSON Test
		</title>
	</head>
	<body>

		<h1>
			JSON Test
		</h1>


		<h3>
			JSON Data:
		</h3>

		<p>
			#jsonData#			
		</p>


		<h3>
			View the JavaScript Console:
		</h3>

		<script type="text/javascript">

			var sJSON = JSON.parse("#JsStringFormat(jsonData)#");
			console.dir(sJSON);

		</script>

	</body>
	</html>

</cfoutput>

Actual Result: Invalid JSON (parsererror SyntaxError: JSON.parse: bad control character in string literal)

Expected Result: Valid JSON

Any Workarounds: Loop the data to clean using a udf function. It would be better if this was dealt with once at the serializeJson function.

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3689989

External Customer Info:
External Company:  
External Customer Name: Pat Moody
External Customer Email:  
External Test Config: My Hardware and Environment details:

ColdFusion 9 & 10 - Firefox. All platforms.

Attachments:

Comments:

Bug was discovered from data saved to MSSQL 2008 database Generally SQL string data from nvarchar tables. Characters probably as a result of users copying and pasting data from other systems / PC's / MAC's etc.
Comment by External U.
13731 | January 07, 2014 05:27:49 PM GMT
encountered the same error. pls fix
Vote by External U.
13734 | January 13, 2014 09:21:09 PM GMT
Ben Nadel has just blogged about this issue! http://www.bennadel.com/blog/2576-Testing-Which-ASCII-Characters-Break-JSON-JavaScript-Object-Notation-Parsing.htm You will see that there are two further ASCII characters that need dealing with. 8232 - Line Separator 8233 - Paragraph Separator
Comment by External U.
13732 | January 13, 2014 09:23:02 PM GMT
I encountered the same issue.
Vote by External U.
13735 | January 14, 2014 01:02:20 PM GMT
[subscribe] -- Adam //////////////
Vote by External U.
13736 | January 15, 2014 03:50:27 AM GMT
Unicode characters 8232 - Line Separator 8233 - Paragraph Separator Break JavaScript code and not the JSON parsing. http://www.bennadel.com/blog/2576-Testing-Which-ASCII-Characters-Break-JSON-JavaScript-Object-Notation-Parsing.htm#comments
Comment by External U.
13733 | January 15, 2014 03:22:57 PM GMT