Skip to content

Commit 328ee12

Browse files
fix: set charset for text/plain responses (#9120)
* fix: charset for text/plain Use settings.DEFAULT_CHARSET * fix: more charset for text/plain ALL THE PLACES
1 parent ae5080b commit 328ee12

File tree

7 files changed

+155
-38
lines changed

7 files changed

+155
-38
lines changed

ietf/api/views.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ class ApiV2PersonExportView(DetailView, JsonExportMixin):
114114
model = Person
115115

116116
def err(self, code, text):
117-
return HttpResponse(text, status=code, content_type='text/plain')
117+
return HttpResponse(
118+
text,
119+
status=code,
120+
content_type=f"text/plain; charset={settings.DEFAULT_CHARSET}",
121+
)
118122

119123
def post(self, request):
120124
querydict = request.POST.copy()
@@ -152,7 +156,11 @@ def post(self, request):
152156
def api_new_meeting_registration_v2(request):
153157
'''REST API to notify the datatracker about a new meeting registration'''
154158
def _http_err(code, text):
155-
return HttpResponse(text, status=code, content_type="text/plain")
159+
return HttpResponse(
160+
text,
161+
status=code,
162+
content_type=f"text/plain; charset={settings.DEFAULT_CHARSET}",
163+
)
156164

157165
def _api_response(result):
158166
return JsonResponse(data={"result": result})
@@ -192,7 +200,11 @@ def _api_response(result):
192200

193201
process_single_registration(reg_data, meeting)
194202

195-
return HttpResponse('Success', status=202, content_type='text/plain')
203+
return HttpResponse(
204+
'Success',
205+
status=202,
206+
content_type=f"text/plain; charset={settings.DEFAULT_CHARSET}",
207+
)
196208

197209

198210
def version(request):
@@ -511,7 +523,11 @@ def related_email_list(request, email):
511523
to Datatracker, via Person object
512524
"""
513525
def _http_err(code, text):
514-
return HttpResponse(text, status=code, content_type="text/plain")
526+
return HttpResponse(
527+
text,
528+
status=code,
529+
content_type=f"text/plain; charset={settings.DEFAULT_CHARSET}",
530+
)
515531

516532
if request.method == "GET":
517533
try:
@@ -637,7 +653,11 @@ def ingest_email_handler(request, test_mode=False):
637653
"""
638654

639655
def _http_err(code, text):
640-
return HttpResponse(text, status=code, content_type="text/plain")
656+
return HttpResponse(
657+
text,
658+
status=code,
659+
content_type=f"text/plain; charset={settings.DEFAULT_CHARSET}",
660+
)
641661

642662
def _api_response(result):
643663
return JsonResponse(data={"result": result})

ietf/doc/views_ballot.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,11 @@ def edit_position(request, name, ballot_id):
257257
@csrf_exempt
258258
def api_set_position(request):
259259
def err(code, text):
260-
return HttpResponse(text, status=code, content_type='text/plain')
260+
return HttpResponse(
261+
text,
262+
status=code,
263+
content_type=f"text/plain; charset={settings.DEFAULT_CHARSET}",
264+
)
261265
if request.method == 'POST':
262266
ad = request.user.person
263267
name = request.POST.get('doc')
@@ -290,7 +294,11 @@ def err(code, text):
290294
addrs, frm, subject, body = build_position_email(ad, doc, pos)
291295
send_mail_text(request, addrs.to, frm, subject, body, cc=addrs.cc)
292296

293-
return HttpResponse("Done", status=200, content_type='text/plain')
297+
return HttpResponse(
298+
"Done",
299+
status=200,
300+
content_type=f"text/plain; charset={settings.DEFAULT_CHARSET}",
301+
)
294302

295303

296304
def build_position_email(balloter, doc, pos):

ietf/iesg/views.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def agenda_txt(request, date=None):
221221
"date": data["date"],
222222
"sections": sorted(data["sections"].items(), key=lambda x:[int(p) for p in x[0].split('.')]),
223223
"domain": Site.objects.get_current().domain,
224-
}, content_type="text/plain; charset=%s"%settings.DEFAULT_CHARSET)
224+
}, content_type=f"text/plain; charset={settings.DEFAULT_CHARSET}")
225225

226226
@role_required('Area Director', 'Secretariat')
227227
def agenda_moderator_package(request, date=None):
@@ -277,14 +277,23 @@ def leaf_section(num, section):
277277
@role_required('Area Director', 'Secretariat')
278278
def agenda_package(request, date=None):
279279
data = agenda_data(date)
280-
return render(request, "iesg/agenda_package.txt", {
280+
return render(
281+
request,
282+
"iesg/agenda_package.txt",
283+
{
281284
"date": data["date"],
282285
"sections": sorted(data["sections"].items()),
283286
"roll_call": data["sections"]["1.1"]["text"],
284287
"minutes": data["sections"]["1.3"]["text"],
285-
"management_items": [(num, section) for num, section in data["sections"].items() if "6" < num < "7"],
288+
"management_items": [
289+
(num, section)
290+
for num, section in data["sections"].items()
291+
if "6" < num < "7"
292+
],
286293
"domain": Site.objects.get_current().domain,
287-
}, content_type='text/plain')
294+
},
295+
content_type=f"text/plain; charset={settings.DEFAULT_CHARSET}",
296+
)
288297

289298

290299
def agenda_documents_txt(request):
@@ -315,7 +324,10 @@ def agenda_documents_txt(request):
315324
d.rev,
316325
)
317326
rows.append("\t".join(row))
318-
return HttpResponse("\n".join(rows), content_type='text/plain')
327+
return HttpResponse(
328+
"\n".join(rows),
329+
content_type=f"text/plain; charset={settings.DEFAULT_CHARSET}",
330+
)
319331

320332
class RescheduleForm(forms.Form):
321333
telechat_date = forms.TypedChoiceField(coerce=lambda x: datetime.datetime.strptime(x, '%Y-%m-%d').date(), empty_value=None, required=False)
@@ -610,4 +622,7 @@ def telechat_agenda_content_manage(request):
610622
@role_required("Secretariat", "IAB Chair", "Area Director")
611623
def telechat_agenda_content_view(request, section):
612624
content = get_object_or_404(TelechatAgendaContent, section__slug=section, section__used=True)
613-
return HttpResponse(content=content.text, content_type="text/plain; charset=utf-8")
625+
return HttpResponse(
626+
content=content.text,
627+
content_type=f"text/plain; charset={settings.DEFAULT_CHARSET}",
628+
)

0 commit comments

Comments
 (0)