Skip to content

JSONP renderer fails to escape U+2028 and U+2029 #2169

Closed
@vfaronov

Description

@vfaronov

When Unicode is enabled for JSON output, the JSONP renderer fails to escape U+2028 and U+2029 which are valid in JSON but invalid in JavaScript.

Try adding this simple model to the example app from the README:

from django.db import models

class Post(models.Model):

    title = models.CharField(max_length=100)
    content = models.TextField()

Create an object like this:

from example.models import Post
Post.objects.create(title=u'Test\u2028', content=u'example')

Then fire up a dev server and make an HTML page with a JSONP request like this:

<script type="text/javascript"
        src="http://127.0.0.1:8000/posts/?format=jsonp"></script>

Open the page in your browser and observe the error console. In Chromium, I get:

Uncaught SyntaxError: Unexpected token ILLEGAL

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions