Edgewall Software
Modify

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#13212 closed defect (fixed)

searching 'ticket:1,2' shows a blank page with UnicodeDecodeError

Reported by: matobaa <matobaa+trac-hacks@…> 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 UnicodeDecodeError when searching a ticket link to query view with non-quickjump.

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 Jun Omae, 5 years ago

Component: generalsearch system
Milestone: 1.4.1

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.

Last edited 5 years ago by Jun Omae (previous) (diff)

comment:2 by Jun Omae, 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/.  
    7676          # if quickjump:
    7777          <dt id="quickjump">
    7878            <a href="${quickjump.href}">${
    79               _('Quickjump to %(name)s', name=quickjump.name)|safe}</a>
     79              tag_('Quickjump to %(name)s', name=quickjump.name)}</a>
    8080          </dt>
    8181          <dd>${quickjump.description}</dd>
    8282          # 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 ff@…, 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 Jun Omae, 5 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: newclosed

Fixed in [17215] and merged in [17216].

Note that the issue which _ function has inconsistent behavior with/without babel package still exists.

comment:5 by Jun Omae, 5 years ago

Owner: set to Jun Omae

#13227 was closed as a duplicate.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jun Omae to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.