summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2014-07-11 15:09:14 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2014-07-11 15:09:14 +0000
commit1a5e3e748a5ea4f48e3e88fa3859db4c186d6ba5 (patch)
treea3748d413eaee6a24dffd6246aa4ec106fc090bf /scripts
parentce1fedb4e5ab82105853c4f3a8e05fb83f62c18e (diff)
downloadmorph-1a5e3e748a5ea4f48e3e88fa3859db4c186d6ba5.tar.gz
Make our use of json binary path safebaserock/richardmaw/bugfix/unicode-safe-json
json only accepts unicode. Various APIs such as file paths and environment variables allow binary data, so we need to support this properly. This patch changes every[1] use of json.load or json.dump to escape non-unicode data strings. This appears exactly as it used to if the input was valid unicode, if it isn't it will insert \xabcd escapes in the place of non-unicode data. When loading back in, if json.load is told to unescape it with `encoding='unicode-escape'` then it will convert it back correctly. This change was primarily to support file paths that weren't valid unicode, where this would choke and die. Now it works, but any tools that parsed the metadata need to unescape the paths. [1]: The interface to the remote repo cache uses json data, but I haven't changes its json.load calls to unescape the data, since the repo caches haven't been made to escape the data.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/list-overlaps4
1 files changed, 2 insertions, 2 deletions
diff --git a/scripts/list-overlaps b/scripts/list-overlaps
index 5fe45a0e..d092ba75 100755
--- a/scripts/list-overlaps
+++ b/scripts/list-overlaps
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright (C) 2011-2012 Codethink Limited
+# Copyright (C) 2011-2014 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -27,7 +27,7 @@ class ListOverlaps(cliapp.Application):
@staticmethod
def _load_overlap(filename):
- data = json.load(open(filename))
+ data = json.load(open(filename), encoding='unicode-escape')
overlaps = dict((frozenset(pair[0]), set(pair[1])) for pair in data)
return overlaps