Modify

Opened 7 years ago

Last modified 2 years ago

#2610 new defect

problems with unicode chars

Reported by: haf@… Owned by: coderanger
Priority: normal Component: CacheSystemPlugin
Severity: major Keywords:
Cc: Trac Release: 0.10

Description

Using unicode chars, the feature does reply with an overall error (see below). In an existing page this is a show-stopper, because the error does not point to the page or char which is malicious. How can I find out which one is the bad unicode character to remove it eventually? Or could unicode support be added to the feature?

Trac[__init__] ERROR: Keys must be str()'s, notunicode.  Convert your unicode strings using  mystring.encode(charset)!
Traceback (most recent call last):
  File "/var/lib/python-support/python2.4/trac/web/main.py", line 387, in dispatch_request     dispatcher.dispatch(req)
  File "/var/lib/python-support/python2.4/trac/web/main.py", line 191, in dispatch     chosen_handler = self._pre_process_request(req, chosen_handler)
  File "/var/lib/python-support/python2.4/trac/web/main.py", line 263, in _pre_process_request     chosen_handler = f.pre_process_request(req, chosen_handler)
  File "build/bdist.linux-i686/egg/cachesystem/filter.py", line 40, in pre_process_request 
  File "/usr/lib/python2.4/site-packages/python_memcached-1.40-py2.4.egg/memcache.py", line 619,  in get check_key(key)
  File "/usr/lib/python2.4/site-packages/python_memcached-1.40-py2.4.egg/memcache.py", line 878, i n check_key raise Client.MemcachedStringEncodingError, ("Keys must be str()'s, not"
MemcachedStringEncodingError: Keys must be str()'s, notunicode.  Convert your unicode strings using mystring.encode(charset)!

Attachments (0)

Change History (2)

comment:1 Changed 7 years ago by anonymous

  • Component changed from TracHacks to CacheSystemPlugin
  • Owner changed from athomas to coderanger

comment:2 Changed 2 years ago by gonzalob@…

I had the same issue. Fixed it in a non-elegant way, but this ticket has 5 years open so that'll have to do.

  • filter.py

     
    3232     
    3333    # IRequestFilter methods 
    3434    def pre_process_request(self, req, handler): 
     35    key = req.path_info.encode('ascii') 
    3536        if isinstance(handler, WikiModule): 
    3637            if req.method == 'GET' and \ 
    3738               req.args.get('action', 'view') == 'view' and \ 
    3839               req.args.get('format') is None and \ 
    3940               req.args.get('version') is None: 
    40                 page = self.client.get(req.path_info) 
     41                page = self.client.get(key) 
    4142                if page is not None: 
    4243                    self.log.debug('CacheFilter: Cache hit on %s', req.path_info) 
    4344                    req.__CACHED_PAGE = page 
     
    4546                else: 
    4647                    req.__PLEASE_CACHE = True 
    4748            elif req.method == 'POST': 
    48                 self.client.delete(req.path_info) 
     49                self.client.delete(key) 
    4950         
    5051        return handler 
    5152         
    5253    def post_process_request(self, req, template, content_type): 
    5354        try: 
    5455            if req.__PLEASE_CACHE: 
    55                 self.client.set(req.path_info, req.hdf.getObj('wiki').writeString(), self.timeout) 
     56                self.client.set(req.path_info.encode('ascii'), req.hdf.getObj('wiki').writeString(), self.timeout) 
    5657        except AttributeError: 
    5758            pass 
    5859        return template, content_type 
     
    6970        req.hdf.copy('wiki', wiki_hdf.hdf) 
    7071        return 'wiki.cs', None 
    7172         
    72      
    73  No newline at end of file 
     73     

Add Comment

Modify Ticket

Action
as new .
Author


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

 
Note: See TracTickets for help on using tickets.