vieten / sequel-pro

Automatically exported from code.google.com/p/sequel-pro
Other
0 stars 0 forks source link

JSON escape end of line #1178

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Steps to reproduce the problem
1. insert a carriage return in a field
2. copy the record in JSON format using the bundle (shortcut ^C)
3. paste and test the resulting object in a javascript console like Firebug: a 
syntax error message is displayed

Solution: escape end of line with \

Example
Object from Sequel Pro (0.9.9.1):
{
    "data":
    [
        {
            "message_id": 1,
            "borrowernumber": 0,
            "branchcode": "*NULL*",
            "message_type": "",
            "message": "line 1
line 2",
            "message_date": "2011-09-07 10:41:08"
        }
    ]
}

Correct object:
{
    "data":
    [
        {
            "message_id": 1,
            "borrowernumber": 0,
            "branchcode": "*NULL*",
            "message_type": "",
            "message": "line 1\
line 2",
            "message_date": "2011-09-07 10:41:08"
        }
    ]
}

Original issue reported on code.google.com by s.bargi...@gmail.com on 7 Sep 2011 at 8:44

GoogleCodeExporter commented 9 years ago

Original comment by stuart02 on 11 Sep 2011 at 10:09

GoogleCodeExporter commented 9 years ago
The suggested solution is incorrect though.
Per specification a JSON string must not contain control characters but must 
use the escaped form "\n"

Original comment by schlabbe...@gmail.com on 12 Sep 2011 at 1:59

GoogleCodeExporter commented 9 years ago

Original comment by mattlangtree on 15 Mar 2012 at 10:55