Code

Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#13114 closed (fixed)

escapejs filter produces invalid JSON according to http://www.json.org/

Reported by: David Danier <david.danier@…> Owned by: nobody
Component: Uncategorized Version: 1.1
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The escapejs filter uses \x.. to escape special characters inside strings. According to http://www.json.org/ this is wrong, \u.... should be used instead.

This actually bite me while using jQuery. Since jQuery 1.4 the JSON-responses get validated, so all my JSON-responses (that are constructed using escapejs) got broken.

Patch to fix this should be rather trivial.

Steps to reproduce:

>>> from django.template.defaultfilters import escapejs
>>> print escapejs('just-a-test')
just\x2Da\x2Dtest

Open http://www.jsonlint.com/ and paste ["just\x2Da\x2Dtest"] , hit Validate.

Attachments (0)

Change History (4)

comment:1 Changed 4 years ago by russellm

  • milestone set to 1.2
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 4 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [12780]) Fixed #13114 -- Modified escapejs to produce output that is JSON compliant. Thanks to David Danier for the report.

comment:3 Changed 4 years ago by russellm

(In [12781]) [1.1.X] Fixed #13114 -- Modified escapejs to produce output that is JSON compliant. Thanks to David Danier for the report.

Backport of r12780 from trunk.

comment:4 Changed 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.