Ticket #2337 (closed defect: fixed)

Opened 9 months ago

Last modified 3 weeks ago

RestController cannot handle non-ascii URLs

Reported by: guest Assigned to:
Priority: normal Milestone: 2.1b2
Component: TurboGears Version: 2.0.1
Severity: normal Keywords:
Cc:

Description

Having a RestController? attached at /controller/, accessing /controller/something will fire it's get_one() method with the rest of the path ('something') passed as method args. This works fine when that something is of ascii chars. If not, we have:

File '/home/myself/src/myproject/myproject/lib/base.py', line 35 in __call__
  return TGController.__call__(self, environ, start_response)
File '/usr/local/lib/python2.6/dist-packages/Pylons-0.9.7-py2.6.egg/pylons/controllers/core.py', line 217 in __call__
  response = self._inspect_call(self.__before__)
File '/usr/local/lib/python2.6/dist-packages/Pylons-0.9.7-py2.6.egg/pylons/controllers/core.py', line 107 in _inspect_call
  result = self._perform_call(func, args)
File '/usr/local/lib/python2.6/dist-packages/TurboGears2-2.0-py2.6.egg/tg/controllers.py', line 792 in _perform_call
  controller, remainder, params = self._get_routing_info(routingArgs)
File '/usr/local/lib/python2.6/dist-packages/TurboGears2-2.0-py2.6.egg/tg/controllers.py', line 462 in _get_routing_info
  controller, remainder = _object_dispatch(self, url_path)
File '/usr/local/lib/python2.6/dist-packages/TurboGears2-2.0-py2.6.egg/tg/controllers.py', line 528 in _object_dispatch
  return _find_restful_dispatch(obj, parent, remainder)
File '/usr/local/lib/python2.6/dist-packages/TurboGears2-2.0-py2.6.egg/tg/controllers.py', line 593 in _find_restful_dispatch
  if remainder and hasattr(obj, remainder[0]) and remainder[0] not in ['new', 'edit']:
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)

So, accessing entities with Unicode PKs via this RestController? is not possible.

Change History

06/27/09 08:20:50 changed by guest

  • version changed from 2.0rc1 to 2.0.1.

11/17/09 08:03:47 changed by jorge.vargas

  • severity changed from major to normal.
  • milestone set to 2.1.

This is indeed a valid bug, however the fix should be to throw an error as unicode URLs should status is not well known. see http://stackoverflow.com/questions/155892/unicode-url-decoding for example.

Therefore I think the RestController? should assume all URLs are ASCII-encoded and complain if they are not rather than, allowing the PK as the OP intended.

01/26/10 20:15:54 changed by percious

  • milestone changed from 2.1 to 2.1b2.

02/22/10 17:51:10 changed by rick446

I've had some trouble reproducing this problem using WebTest? -- it seems that WebTest? converts everything (including URLs) to str() when creating the request. I tried reproducing by encoding the URL as UTF-8, but this appears to work just fine. So without a failing test case, I'm not sure what we can do here.

02/23/10 14:05:24 changed by percious

  • status changed from new to closed.
  • resolution set to fixed.

I tested this in 2.1 on FFx, Safari, curl, and wget and found it to work (aside from unittesting) Closing....