Code

Opened 6 years ago

Closed 5 years ago

Last modified 3 years ago

#9580 closed (wontfix)

javascript_quote should accept SafeUnicode

Reported by: boyerchen@… Owned by: keithb
Component: Uncategorized Version: 1.0-beta
Severity: Keywords:
Cc: kbussell@… Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

django.utils.javascript_quote does not accept a SafeUnicode instance as argument and raises a TypeError.

Expected behavior:
Treat SafeUnicode as usual unicode string.

Attachments (0)

Change History (7)

comment:1 Changed 5 years ago by jacob

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

comment:2 Changed 5 years ago by keithb

  • Owner changed from nobody to keithb
  • Status changed from new to assigned

comment:3 Changed 5 years ago by keithb

  • Triage Stage changed from Accepted to Design decision needed

django.utils is for tools internal to Django, and nothing at this layer currently knows about safe strings.

How are you using this function? Note: If you're calling this from a template, you can use django.template.defaultfilters.escapejs.

comment:4 Changed 5 years ago by keithb

  • Cc kbussell@… added

comment:5 follow-up: Changed 5 years ago by Passy

I used it to escape a rendered form in an ajax response to load it afterwards into a wrapper element with javascript. I currently decode it as UTF-8, but I guess supporting a safe string would be more intuitive.

comment:6 in reply to: ↑ 5 Changed 5 years ago by keithb

  • Resolution set to wontfix
  • Status changed from assigned to closed

Replying to Passy:

I used it to escape a rendered form in an ajax response to load it afterwards into a wrapper element with javascript. I currently decode it as UTF-8, but I guess supporting a safe string would be more intuitive.

Use django.template.defaultfilters.escapejs instead of javascript_quote. (You don't need to limit use of template filters to template rendering. Filters are just functions that operate on strings, and safe strings.)

(resolution approved by Jacob)

comment:7 Changed 3 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 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.