Opened 5 years ago

Closed 5 years ago

Last modified 4 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.

Change History (4)

comment:1 Changed 5 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 5 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 5 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 4 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

Note: See TracTickets for help on using tickets.
Back to Top