Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast everything to a string #2252

Merged
merged 2 commits into from Apr 27, 2016

Conversation

Projects
None yet
3 participants
@erasche
Copy link
Member

commented Apr 26, 2016

cgi.escape doesn't work on non-strings. Fixes #2251

cc @martenson

Cast everything to a string
cgi.escape doesn't work on non-strings

@erasche erasche added this to the 16.07 milestone Apr 26, 2016

@@ -208,7 +208,7 @@ def create_report( self, user, email='', message='', **kwd ):

# Escape all of the content for use in the HTML report
for parameter in report_variables.keys():
report_variables[parameter] = cgi.escape(report_variables[parameter])
report_variables[parameter] = cgi.escape(str(report_variables[parameter]))

This comment has been minimized.

Copy link
@nsoranzo

nsoranzo Apr 27, 2016

Member

Not sure if the following can happen, but str() may fail if report_variables[parameter] is of type unicode:

>>> foo = u'é'
>>> str(foo)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 0: ordinal not in range(128)

So I'd suggest either:

import six
...
            report_variables[parameter] = cgi.escape(report_variables[parameter] if isinstance(report_variables[parameter], six.string_types) else str(report_variables[parameter]))

or:

from galaxy.util import unicodify
...
            report_variables[parameter] = cgi.escape(unicodify(report_variables[parameter]))
@erasche

This comment has been minimized.

Copy link
Member Author

commented Apr 27, 2016

Unrelated TS failure.

@nsoranzo

This comment has been minimized.

Copy link
Member

commented Apr 27, 2016

👍

@martenson

This comment has been minimized.

Copy link
Member

commented Apr 27, 2016

thanks @erasche and @nsoranzo

@martenson martenson merged commit b51a186 into galaxyproject:dev Apr 27, 2016

3 of 4 checks passed

toolshed test Build finished.
Details
api test Build finished.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
framework test Build finished.
Details

@erasche erasche deleted the erasche:fix-2251 branch Dec 19, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.