Opened 9 years ago

Closed 9 years ago

#24962 closed Bug (fixed)

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

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 Tim Graham)

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)

Attachments (4)

bugged.png (14.7 KB ) - added by Alejandro Dubrovsky 9 years ago.
List with bug in it. Those two black entries have newlines in them
fixed.png (14.8 KB ) - added by Alejandro Dubrovsky 9 years ago.
Same list fixed
djangoquotepatch.txt (437 bytes ) - added by Alejandro Dubrovsky 9 years ago.
Two-character patch wrt github master as of now
djangoregression.txt (909 bytes ) - added by Alejandro Dubrovsky 9 years ago.
regressiontest

Download all attachments as: .zip

Change History (8)

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

comment:1 by Tim Graham, 9 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted

A regression test is also needed.

by Alejandro Dubrovsky, 9 years ago

Attachment: djangoregression.txt added

regressiontest

comment:2 by Alejandro Dubrovsky, 9 years ago

I don't know almost anything about regression tests but I've attached my naive attempt

comment:3 by Tim Graham, 9 years ago

Description: modified (diff)
Needs tests: unset

comment:4 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 20c6ba6f:

Fixed #24962 -- Added newline to characters escaped by contrib.admin.utils.quote()

Thanks alito for the report and patch.

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