Skip to content
This repository was archived by the owner on Sep 7, 2018. It is now read-only.

Commit 2f94209

Browse files
committed
Fixed a bug that caused by wrong Accept header from IE8.
1 parent 14ab463 commit 2f94209

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

langdev/web/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,19 +319,23 @@ def render(template_name, value, **context):
319319
.. todo:: Adding :mailheader:`Vary` header.
320320
321321
"""
322-
accept_mimetypes = flask.request.accept_mimetypes
323-
if len(accept_mimetypes) == 1 and accept_mimetypes.values()[0] == '*/*':
324-
accept_mimetypes = [(default_content_type, 1)]
325-
accept_mimetypes = werkzeug.datastructures.MIMEAccept(accept_mimetypes)
326322
jinja_env = flask.current_app.jinja_env
327323
def _tpl_avail(postfix):
328324
try:
329325
jinja_env.get_template(template_name + postfix)
330326
except jinja2.TemplateNotFound:
331327
return False
332328
return True
333-
types = (mimetype for mimetype, f in content_types.iteritems()
334-
if callable(f) or not f.startswith('.') or _tpl_avail(f))
329+
types = [mimetype for mimetype, f in content_types.iteritems()
330+
if callable(f) or not f.startswith('.') or _tpl_avail(f)]
331+
# workaround for IE8. it sent wrong Accept header like below -_-
332+
# " Accept: image/pjpeg, image/pjpeg, image/gif, image/jpeg, */* "
333+
m = ((mime, q) for mime, q in flask.request.accept_mimetypes
334+
if mime in types or mime == '*/*')
335+
accept_mimetypes = werkzeug.datastructures.MIMEAccept(m)
336+
if len(accept_mimetypes) == 1 and accept_mimetypes.values()[0] == '*/*':
337+
accept_mimetypes = [(default_content_type, 1)]
338+
accept_mimetypes = werkzeug.datastructures.MIMEAccept(accept_mimetypes)
335339
content_type = accept_mimetypes.best_match(types)
336340
try:
337341
serializer = content_types[content_type]

langdev/web/templates/forum/posts.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
{% if view == 'summary' %}
1717
{% set grouped = posts|groupby('sticky') %}
1818
{% set posts = (grouped[True]|default({})).list %}
19-
{% set other_posts = grouped[False].list %}
19+
{% set other_posts = (grouped[False]|default({})).list %}
2020
{% endif %}
2121
{% if posts %}
2222
<table>

0 commit comments

Comments
 (0)