#13212 closed defect (fixed)
searching 'ticket:1,2' shows a blank page with UnicodeDecodeError
Reported by: | Owned by: | Jun Omae | |
---|---|---|---|
Priority: | normal | Milestone: | 1.4.1 |
Component: | search system | Version: | 1.4 |
Severity: | normal | Keywords: | |
Cc: | matobaa+trac-hacks@… | Branch: | |
Release Notes: |
Fixed |
||
API Changes: | |||
Internal Changes: |
Description
click search on mainnav, input ticket:1,2
in a textbox then click 'search' shows a blank page with log follows:
File "c:\trac\1.4\.venv\lib\site-packages\trac\templates\theme.html", line 128, in block "body" # block content File "c:\trac\1.4\.venv\lib\site-packages\trac\search\templates\search.html", line 79, in block "content" _('Quickjump to %(name)s', name=quickjump.name)|safe}</a> File "c:\trac\1.4\.venv\lib\site-packages\jinja2\filters.py", line 887, in do_mark_safe return Markup(value) File "c:\trac\1.4\.venv\lib\site-packages\markupsafe\__init__.py", line 74, in __new__ return text_type.__new__(cls, base) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 26: ordinal not in range(128)
System Information User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36 Package Version Trac 1.4 Genshi (not installed, some old plugins may not work as expected) Jinja2 2.10.1 pysqlite 2.6.0 Python 2.7.16 (v2.7.16:413a49145e, Mar 4 2019, 01:37:19) [MSC v.1500 64 bit (AMD64)] setuptools 41.2.0 SQLite 3.14.2 jQuery 1.12.4 jQuery UI 1.12.1 jQuery Timepicker 1.6.3 Configuration database sqlite:db/trac.db
Attachments (0)
Change History (5)
comment:1 by , 5 years ago
Component: | general → search system |
---|---|
Milestone: | → 1.4.1 |
comment:2 by , 5 years ago
We should use tag_
rather than _
because quickjump.name
in search.html is a Fragment
instance.
-
trac/search/templates/search.html
diff --git a/trac/search/templates/search.html b/trac/search/templates/search.html index 273aa1c7b..f77ff1e1d 100644
a b history and logs, available at https://trac.edgewall.org/. 76 76 # if quickjump: 77 77 <dt id="quickjump"> 78 78 <a href="${quickjump.href}">${ 79 _('Quickjump to %(name)s', name=quickjump.name)|safe}</a>79 tag_('Quickjump to %(name)s', name=quickjump.name)}</a> 80 80 </dt> 81 81 <dd>${quickjump.description}</dd> 82 82 # endif
Another considering, _
function returns inconsistent instance with/without Babel. It would be good that the _
function always returns a unicode instance.
Without Babel
>>> from trac.util.html import tag >>> from trac.util.translation import _, tag_, has_babel >>> has_babel False >>> _('Quickjump to %(name)s', name=tag.em(u'ticket:1,\u200B2')) 'Quickjump to <em>ticket:1,\xe2\x80\x8b2</em>' # ==> bytes instance >>> tag_('Quickjump to %(name)s', name=tag.em(u'ticket:1,\u200B2')).__html__() Markup(u'Quickjump to <em>ticket:1,\u200b2</em>')
With Babel
>>> from trac.util.html import tag >>> from trac.util.translation import _, tag_, has_babel, make_activable >>> has_babel True >>> make_activable(lambda: 'en_US') >>> _('Quickjump to %(name)s', name=tag.em(u'ticket:1,\u200B2')) u'Quickjump to <em>ticket:1,\u200b2</em>' # ==> unicode instance >>> tag_('Quickjump to %(name)s', name=tag.em(u'ticket:1,\u200B2')).__html__() Markup(u'Quickjump to <em>ticket:1,\u200b2</em>')
comment:3 by , 5 years ago
I got the same error when searching for something which looks like an email address (a@b.c
will do, leaving something away not). Changing the line to use tag_
solved the problem for me.
comment:4 by , 5 years ago
Release Notes: | modified (diff) |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Good catch! Thanks.
Reproduced it if Babel is not installed. Unable to reproduce if Babel is installed. Also, visiting
search:?q=ticket:1,2&noquickjump=1
link would directly lead the issue.