Modify

Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#5575 closed defect (fixed)

[Patch] UnicodeEncodeError on Japanese tag

Reported by: nac Owned by: otaku42
Priority: normal Component: TagsPlugin
Severity: major Keywords: unicode
Cc: Trac Release: 0.11

Description

I got UnicodeEncodeError when I clicked Japanese tag in. (Japanese tag itself can be entered and displayed with tag macro like tag cloud.)

Error is

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-4: ordinal not in range(128)

Here is traceback;

File "/usr/lib/python2.5/site-packages/trac/web/main.py", line 435, in _dispatch_request
  dispatcher.dispatch(req)
File "/usr/lib/python2.5/site-packages/trac/web/main.py", line 205, in dispatch
  resp = chosen_handler.process_request(req)
File "build/bdist.linux-i586/egg/tractags/web_ui.py", line 99, in process_requestFile "build/bdist.linux-i586/egg/tractags/macros.py", line 80, in expand_macroFile "build/bdist.linux-i586/egg/tractags/macros.py", line 80, in <lambda>

And my trac system is

Trac0.11.4
Python2.5.4 (r254:67916, May 24 2009, 15:20:27) [GCC 4.1.2(Gentoo 4.1.2 p1.1)]
setuptools0.6c9
SQLite3.6.14
pysqlite2.3.2
Genshi0.5.1
mod_python3.3.1
Pygments1.0
jQuery1.2.6

Attachments (0)

Change History (11)

comment:1 Changed 5 years ago by nac

Here is a simple patch.

$ diff -c macros.py.org  macros.py
*** macros.py.org	2009-07-29 06:51:30.997066248 +0900
--- macros.py	2009-07-29 07:00:59.698785287 +0900
***************
*** 77,83 ****
  
          ul = builder.ul(class_='taglist')
          for resource, tags in sorted(query_result,
!                                      key=lambda r: str(r[0].id)):
              tags = sorted(tags)
              if tags:
                  rendered_tags = [
--- 77,83 ----
  
          ul = builder.ul(class_='taglist')
          for resource, tags in sorted(query_result,
!                                      key=lambda r: str(r[0].id.encode('utf-8'))):
              tags = sorted(tags)
              if tags:
                  rendered_tags = [

comment:2 Changed 4 years ago by rjollos

  • Summary changed from UnicodeEncodeError on Japanese tag to [Patch] UnicodeEncodeError on Japanese tag

comment:3 Changed 4 years ago by nac

Using to_unicode function can resolve this problem and it will be better than .encode method.

from trac.util.text import to_unicode

        for resource, tags in sorted(query_result,
                                     #key=lambda r: str(r[0].id)):
                                     key=lambda r: to_unicode(r[0].id)):

comment:4 Changed 4 years ago by vchoi@…

This also happens to portuguese characters.

comment:5 follow-up: Changed 4 years ago by hasienda

  • Keywords unicode added
  • Owner changed from athomas to otaku42

This has been fixed in trunk with changeset [3875] more than 2 years ago (see #2493).

Anyway, this doesn't went in the other branches and I feel like to_unicode from Trac would be better coding style anyway, as you see much better what happens from it's name.

So I'll change this in trunk and will ask Michael (otaku42), the current maintainer, to backport it to the other branch(es).

comment:6 Changed 4 years ago by hasienda

#6908 has been closed as a duplicate of this ticket.

comment:7 in reply to: ↑ 5 ; follow-ups: Changed 4 years ago by otaku42

  • Status changed from new to assigned

Replying to hasienda:

So I'll change this in trunk and will ask Michael (otaku42), the current maintainer, to backport it to the other branch(es).

Yes, please do so. Not sure if I backport that to earlier versions, though. I think it would be good to get a new version out that contains either just recent bug fixes, or maybe also new features such as i18n.

comment:8 in reply to: ↑ 7 Changed 4 years ago by vchoi@…

Replying to otaku42:

Yes, please do so. Not sure if I backport that to earlier versions, though. I think it would be good to get a new version out that contains either just recent bug fixes, or maybe also new features such as i18n.

I also think so.

comment:9 in reply to: ↑ 7 ; follow-up: Changed 4 years ago by hasienda

Replying to otaku42:

Replying to hasienda:

So I'll change this in trunk and will ask Michael (otaku42), the current maintainer, to backport it to the other branch(es).

Yes, please do so. Not sure if I backport that to earlier versions, though. I think it would be good to get a new version out that contains either just recent bug fixes, or maybe also new features such as i18n.

Ok, at least i18n has been added to trunk today, finally, and I'll rework code related to this issue now.

How about doing a 0.6.1 with recent bug fixes and a reserve i18n for the next major release? At least this has been prepared by pushing trunk version to 0.7dev in changeset [9316].

comment:10 Changed 4 years ago by hasienda

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [9322]) TagsPlugin: Rework string encoding for (non-ASCII) tag names, closes #5575.

This has been fixed in other branches in a different way before, however applying a method from Trac could be preferred.

comment:11 in reply to: ↑ 9 Changed 4 years ago by otaku42

Replying to hasienda:

How about doing a 0.6.1 with recent bug fixes and a reserve i18n for the next major release?

No objections from my side on this one.

Add Comment

Modify Ticket

Action
as closed The owner will remain otaku42.
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.