Skip to content

Method escape_value is not robust to encodings #2

Description

@Farmhouse121

It uses str uniformly. This breaks with differing or broken unicode encodings. It also does uncessary replace operations when the argument is not a string. The following works better:

def escape_value(self, data):
if data is None:
return ''

if type(data) in (str,unicode):
    data = data.encode(sys.getdefaultencoding(),"ignore")
    data = data.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;')

else:
    data = str(data)

return data

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions