Code

Opened 6 years ago

Closed 4 years ago

#9211 closed (duplicate)

Objects with newlines in representation break popup JavaScript in the admin

Reported by: jbronn Owned by: nobody
Component: contrib.admin Version: 1.0
Severity: Keywords: admin popup newline carriage
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When you have these models:

class Note(models.Model):
    text = models.TextField()

    def __unicode__(self):
        return self.text

class Person(models.Model):
    name = models.CharField(max_length=25)
    note = models.ForeignKey(Note)

    def __unicode__(self):
        return self.name

And the following in admin.py:

from django.contrib import admin
from models import Note, Person

admin.site.register(Note)
admin.site.register(Person)

When entering a Person model in the admin a new may Note created by clicking the plus icon next to the selection list. If the person entering the note presses return and puts newlines in the TextField, the dismissAddAnotherPopup JavaScript chokes on the Notes representation.

Attached is a patch that escapes carriage returns, however, I want some discussion on whether there needs to be any other escaping performed.

Attachments (1)

admin_escape_popup_newlines.diff (811 bytes) - added by jbronn 6 years ago.

Download all attachments as: .zip

Change History (5)

Changed 6 years ago by jbronn

comment:1 Changed 6 years ago by mtredinnick

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

Should this be done with escapejs() instead? That would handle the cases you've identified and a few dozen others as well. At first glance, it looks like the right tool here, but I might be missing something.

comment:2 Changed 5 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:3 Changed 4 years ago by ramiro

Duplicate of #2986.

comment:4 Changed 4 years ago by ramiro

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

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.