zenhack / simp_le

Simple Let's Encrypt client
GNU General Public License v3.0
224 stars 38 forks source link

Add basic domains sanitization to Vhost.decode() #67

Closed buchdag closed 7 years ago

buchdag commented 7 years ago

This PR aims to provide basic sanitization for domain names:

The utf-8 check is currently causing an unexpected doctest error on python 2.6 but not on 2.7, I haven't found a solution yet, any help is welcome:

ERROR: Doctest: simp_le.Vhost.decode
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/python/2.6.9/lib/python2.6/doctest.py", line 2158, in runTest
    test, out=new.write, clear_globs=False)
  File "/opt/python/2.6.9/lib/python2.6/doctest.py", line 1391, in run
    return self.__run(test, compileflags, out)
  File "/opt/python/2.6.9/lib/python2.6/doctest.py", line 1277, in __run
    got += _exception_traceback(exc_info)
  File "/opt/python/2.6.9/lib/python2.6/doctest.py", line 244, in _exception_traceback
    traceback.print_exception(exc_type, exc_val, exc_tb, file=excout)
  File "/opt/python/2.6.9/lib/python2.6/traceback.py", line 125, in print_exception
    print_tb(tb, limit, file)
  File "/opt/python/2.6.9/lib/python2.6/traceback.py", line 69, in print_tb
    line = linecache.getline(filename, lineno, f.f_globals)
  File "/home/travis/virtualenv/python2.6.9/lib/python2.6/linecache.py", line 14, in getline
    lines = getlines(filename, module_globals)
  File "/opt/python/2.6.9/lib/python2.6/doctest.py", line 1336, in __patched_linecache_getlines
    source = example.source.encode('ascii', 'backslashreplace')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 14: ordinal not in range(128)
zenhack commented 7 years ago

I managed to get it to work on centos 6.7 (which has python 2.6.6 as the system python) by replacing the literal utf-8 with an escaped unicode literal: u'\u4f8b\u5982.\u4e2d\u56fd'.

buchdag commented 7 years ago

Thanks, that worked, I thought that python 3 would choke on u''.

I had to disable a pylint warning for the Vhost.decode() method, and I removed the utf-8 declaration header.

zenhack commented 7 years ago

Yeah, it was missing in python 3.0, adding back in 3.1 to ease compatiblility iirc.

This looks good to me; assuming travis passes I'll merge it.

buchdag commented 7 years ago

Any idea why Travis appears to be stuck on GitHub while it's not ?

Restarting the build seems to have done the trick for my fork.

zenhack commented 7 years ago

No idea. I decided not to worry about it; travis has transient issues like that every now and then.