ColdFusion 10.0  -  Bug 3689989

Created on Tuesday, January 7, 2014

Login for more options

Title

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

Description

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.

Test Configuration

My Hardware and Environment details:
ColdFusion 9 & 10 - Firefox. All platforms.

App Language(s) English
OS Language(s) English
Platform(s) Windows 7 64-bit
Browser(s)

Notes (3)

  • Pat Moody

    12:52:57 PM GMT+00:00 Jan 15, 2014

    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

  • Pat Moody

    6:53:02 PM GMT+00:00 Jan 13, 2014

    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

  • Pat Moody

    2:57:49 PM GMT+00:00 Jan 7, 2014

    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.

Duplicate ID
Reported By Pat Moody

Status

State Closed
Status Fixed
Reason

Importance

Priority 3-High
Frequency All users will encounter
Failure Type Incorrectly Functioning
Product Area AJAX

Build

Found In Build Final
Fixed In Build

Attachments (0)

No Files Attached

Votes (3)

  • Adam Cameron

    1:20:27 AM GMT+00:00 Jan 15, 2014

    [subscribe]

    --
    Adam
    //////////////

  • yujust

    10:32:20 AM GMT+00:00 Jan 14, 2014

    I encountered the same issue.

  • Henry Ho

    6:51:09 PM GMT+00:00 Jan 13, 2014

    encountered the same error. pls fix

Your session has expired! Click to login
Current form data will be preserved

Cancel