1.45 - host parsing bugs

Bug #529855 reported by Roger Binns
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Python Memcached
Fix Released
Medium
Sean Reifschneider

Bug Description

I just upgraded from 1.40 to 1.45 and have found some bugs in Host.__init__ for parsing a host.

Firstly a name without a colon is rejected. For example is host is "localhost" then you get:

   ValueError: Unable to parse connection string: "localhost"

This is because the last pattern requires a colon and port number, but the middle pattern which doesn't requires a "inet:" prefix.

Further down the port is set by this:

  self.port = int(hostData.get('port', 11211))

However the groupdict does not work that way. It returns None rather than the second parameter that would be a default for normal dicts:

  >>> x.groupdict().get("port")
  >>> x.groupdict().get("port", 12)
  >>>

The fix is to explicitly check the get result and if None then use the default.

The fix for the earlier problem ("localhost" being rejected is to make the colon and port number be optional):

  x=re.match(r'^(?P<host>[^:]+)(:(?P<port>[0-9]+))?$', host)

Changed in python-memcached:
status: New → Fix Committed
importance: Undecided → Medium
assignee: nobody → Sean Reifschneider (jafo)
Changed in python-memcached:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.