Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2337 (closed defect: fixed)

Opened 10 years ago

Last modified 9 years ago

RestController cannot handle non-ascii URLs

Reported by: guest Owned by:
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

comment:1 Changed 10 years ago by guest

  • Version changed from 2.0rc1 to 2.0.1

comment:2 Changed 10 years ago 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.

comment:3 Changed 9 years ago by percious

  • Milestone changed from 2.1 to 2.1b2

comment:4 Changed 9 years ago 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.

comment:5 Changed 9 years ago 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....

Note: See TracTickets for help on using tickets.