Opened 9 years ago

Last modified 9 years ago

#24962 closed Bug

Objects with primary keys containing newlines do not get links to being edited in the admin list view — at Initial Version

Reported by: Alejandro Dubrovsky Owned by: nobody
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: yes

Description

The admin list view of an object lists each object and does a

reverse('admin:%s_%s_change' % (self.opts.app_label, self.opts.model_name), args=(quote(pk),), current_app=self.model_admin.admin_site.name)

to assign a change url for each one, skipping the link if the reverse fails. The 'quote' function there escapes a whole bunch of characters so as not to confuse the url pattern matcher but it forgets to escape newline.

Therefore, a model like this:

class Name(models.Model):

name = models.TextField(primary_key=True)

with:
n = Name('John')
n.save()
o = Name('Have a \n newline')
o.save()

will list a link for John, but no link for 'Have a
newline'

(The bug actually is triggered in quite a few other places in admin but the list view is the easiest one to see. I've attached some screenshots that I prepared earlier)

Change is a 2-character change to quote \n as well (attached)

Change History (3)

by Alejandro Dubrovsky, 9 years ago

Attachment: bugged.png added

List with bug in it. Those two black entries have newlines in them

by Alejandro Dubrovsky, 9 years ago

Attachment: fixed.png added

Same list fixed

by Alejandro Dubrovsky, 9 years ago

Attachment: djangoquotepatch.txt added

Two-character patch wrt github master as of now

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