HtpasswdFile does not like empty lines

Issue #73 resolved
Robert Buchholz
created an issue

Given the following passwd file:

user1:somehash
user2:somehash

# legacy users
user3:somehash

and code as follows:

>>> import passlib
>>> passlib.__version__
'1.6.5'
>>> from passlib.apache import HtpasswdFile
>>> HtpasswdFile('svn.htpasswd')

I get

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "python2.6/site-packages/passlib/apache.py", line 583, in __init__
    super(HtpasswdFile, self).__init__(path, **kwds)
  File "python2.6/site-packages/passlib/apache.py", line 166, in __init__
    self.load()
  File "python2.6/site-packages/passlib/apache.py", line 236, in load
    self._load_lines(fh)
  File "python2.6/site-packages/passlib/apache.py", line 261, in _load_lines
    key, value = parse(line, idx+1)
  File "python2.6/site-packages/passlib/apache.py", line 590, in _parse_record
    % lineno)
ValueError: malformed htpasswd file (error reading line 3)

This file is perfectly acceptable to my apache, so why does passlib consider it malformed?

Comments (6)

  1. Eli Collins repo owner

    Thanks for reporting this!

    Definitely a glitch in passlib, the parser overly strict. Mainly because there isn't an official spec for the htpasswd format, and no one's reporting this until now :)

    After a quick look at the htpasswd source (https://github.com/apache/httpd/blob/trunk/support/htpasswd.c), it looks like blank lines and comment lines are both accepted, but will be kicked out by Passlib. This shouldn't be too hard to fix, and will have it out in the next bugfix release.

  2. Eli Collins repo owner

    Doing this right turned out to require a few more changes than a simple bugfix release should include :)

    As of rev b9561a7d2f62, the code now not only handles blank lines, but preserves whitespace & comments through load/save (another TODO item that had been lingering).

    Will be included in the 1.7 release, due hopefully in june/july 2016.

  3. Log in to comment