Title:
serializeJson not cleaning most of the first 31 characters in the ASCII table.
| View in TrackerProblem 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: