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 Version 3
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 (last modified by )
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 (7)
by , 9 years ago
Attachment: | bugged.png added |
---|
by , 9 years ago
Attachment: | djangoquotepatch.txt added |
---|
Two-character patch wrt github master as of now
comment:1 by , 9 years ago
Needs tests: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
A regression test is also needed.
comment:2 by , 9 years ago
I don't know almost anything about regression tests but I've attached my naive attempt
comment:3 by , 9 years ago
Description: | modified (diff) |
---|---|
Needs tests: | unset |
List with bug in it. Those two black entries have newlines in them