jasmine/jasmine-py

decode error in standalone.py when file encoding not recognized

skarger opened this issue · 1 comments

standalone.py attempts to detect the encoding of each file to serve using chardet.

This fails when the encoding is not detected. I think the behavior is new as of #28.

I'm seeing the issue with png and woff2 files from an included library. chardet.detect(raw_contents) comes back with None for the encoding:

Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> path = '/usr/app/static/scripts/bower_components/font-awesome/fonts/fontawesome-webfont.woff2'
>>> import chardet
>>> raw_contents = open(path, 'rb').read()
>>> encoding = chardet.detect(raw_contents)['encoding']
>>> encoding is None
True
>>> chardet.detect(raw_contents)
{'confidence': 0.0, 'encoding': None}

Printing the output in the serve method of standalone.py I see things like this:

filetype src, filename scripts/bower_components/leaflet/dist/images/marker-shadow.png
encoding None
filetype src, filename scripts/bower_components/font-awesome/fonts/fontawesome-webfont.woff2
encoding None

Then it errors at https://github.com/jasmine/jasmine-py/blob/master/jasmine/standalone.py#L70 when running xvfb-run jasmine-ci --browser firefox.

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/cherrypy/wsgiserver/wsgiserver2.py", line 1358, in communicate
    req.respond()
  File "/usr/local/lib/python2.7/dist-packages/cherrypy/wsgiserver/wsgiserver2.py", line 873, in respond
    self.server.gateway(self).respond()
  File "/usr/local/lib/python2.7/dist-packages/cherrypy/wsgiserver/wsgiserver2.py", line 2272, in respond
    response = self.req.server.wsgi_app(self.env, self.start_response)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python2.7/dist-packages/jasmine/standalone.py", line 38, in serve
    contents = self._decode_raw(raw_contents)
  File "/usr/local/lib/python2.7/dist-packages/jasmine/standalone.py", line 70, in _decode_raw
    contents = raw_contents.decode(encoding)
TypeError: decode() argument 1 must be string, not None
TypeError('decode() argument 1 must be string, not None',)
TypeError('decode() argument 1 must be string, not None',)

It's possible that I'm missing a required configuration for jasmine-py or jasmine.yml? Or maybe it's a bug in jasmine-py. Thanks in advance for any insight you have.

Gerg commented

The is definitely a bug with jasmine-py. There probably just needs to be None check before trying to decode.