Code

Opened 4 months ago

Closed 4 months ago

Last modified 4 months ago

#21620 closed Bug (duplicate)

HttpResponseBase._convert_to_charset STILL complains about newline it inserted itself

Reported by: poly Owned by: nobody
Component: HTTP handling Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

As reported in #20889, a header that is so long will be splitted by email.header.Header into several lines. And tim fixed it here.
However, when the length of the header exceeds certain limit, email.header.Header still inserts newlines, which raises the great BadHeaderError.

FYI:

# coding=utf-8
from django.http import HttpResponse
h = HttpResponse()
f = '\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91'.decode('utf-8')
h['Content-Disposition'] = u'attachment; filename="%s"' % f

This snippet works when tim's patch is applied, but the next doesn't

# coding=utf-8
from django.http import HttpResponse
h = HttpResponse()
f = '\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91\xe6\x88\x91'.decode('utf-8')
h['Content-Disposition'] = u'attachment; filename="%s"' % f

As you can see, the only difference is that the second one has a longer header value.

Also, I'm wondering why we need to encode those headers in the mime way, since most browsers don't support them(at least chrome), why can't we just encode them in latin1 like what flask does.
Thanks for your time.

Attachments (0)

Change History (2)

comment:1 Changed 4 months ago by bmispelon

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

Hi,

In order to keep the discussion in one place, can you reopen #20889 instead?

Thanks.

comment:2 Changed 4 months ago by poly

Sure, please refer to #20889.

Last edited 4 months ago by poly (previous) (diff)

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.