Commit 28c78ff0 authored by Benjamin Fischer's avatar Benjamin Fischer
Browse files

Python/JSON: use ensure_ascii=True with every dumps for safety

refs #2403
parent c19b1acf
......@@ -104,7 +104,7 @@ class RootController(AbstractController):
parsed_preference = {}
for key2, value2 in value.items():
parsed_preference[key2] = JSON.loads(value2)
parsed_preferences[key] = JSON.dumps(parsed_preference)
parsed_preferences[key] = JSON.dumps(parsed_preference, ensure_ascii=True)
except:
logger.exception("parse prefernces")
return parsed_preferences
......@@ -173,7 +173,7 @@ class RootController(AbstractController):
"is_guest" : cherrypy.session.get("is_guest", False),
"is_admin" : user.serveradmin,
"workspace_action": self.workspace_action,
"extensions" : JSON.dumps(extensions),
"extensions" : JSON.dumps(extensions, ensure_ascii=True),
"cache_bust" : self.cache_bust,
}
data.update(preferences)
......
......@@ -193,7 +193,7 @@ class WorkspaceState(Base):
del current_state[id]
elif identifier:
current_state[id] = identifier
workspace_state.state = json.dumps(current_state)
workspace_state.state = json.dumps(current_state, ensure_ascii=True)
else:
workspace_state.state = unicode(state)
workspace_state.timestamp = datetime.now()
......
......@@ -234,7 +234,7 @@ class FileSystem(object):
'path': base
}
if encode_json:
return json.dumps(data)
return json.dumps(data, ensure_ascii=True)
else:
return data
......@@ -281,7 +281,7 @@ class FileSystem(object):
suggestion += '/'
suggestions.append(suggestion)
return suggestions if not encode_json else json.dumps(suggestions)
return suggestions if not encode_json else json.dumps(suggestions, ensure_ascii=True)
def cut_slashs(self, path):
path = self.expand(path)
......@@ -446,7 +446,7 @@ class FileSystem(object):
"mtime": 0,
"success": False,
"watch_error": ""
})
}, ensure_ascii=True)
if utf8:
content = content.encode('utf8')
try:
......@@ -468,7 +468,7 @@ class FileSystem(object):
"success": mtime > 0 and self.checkPermissions(path),
"watch_error": watch_error,
"path": path
})
}, ensure_ascii=True)
def get_file(self, path, binary=False,
utf8=False, window_id=None, view_id=None, watch_id=None, max_size=20):
......@@ -481,7 +481,7 @@ class FileSystem(object):
# actual function
path = self.expand(path)
try:
if os.path.getsize(path) > max_size:
content = ""
......@@ -492,15 +492,15 @@ class FileSystem(object):
writable = False
error = None
size_limit = True
else:
with open(path, "rb" if binary else "r") as f:
content = f.read()
content = f.read()
writable = self.checkPermissions(path)
error = None
size_limit = False
if utf8:
content = content.decode('utf8')
......@@ -521,7 +521,7 @@ class FileSystem(object):
"size_limit": size_limit,
"max_size": max_size/(1024*1024),
"error": error
})
}, ensure_ascii=True)
def checkPermissions(self, path, permission=os.W_OK):
return os.access(path, permission)
......@@ -733,13 +733,13 @@ class FileSystem(object):
"content": data,
"success": True,
"mtime": mtime
})
}, ensure_ascii=True)
except Exception as e:
return json.dumps({
"content": "",
"success": False,
"error": str(e)
})
}, ensure_ascii=True)
def set_workspaceini(self, request):
try:
......
......@@ -72,7 +72,7 @@ def remove_session(window_id):
del POLLING_TIMESTAMPS[window_id]
vispa.publish("bus.session_removed", window_id, user_id)
if last_lession:
logger.debug("no more user sessions %d" % int(user_id))
vispa.publish("bus.all_user_sessions_removed", int(user_id))
......@@ -128,7 +128,7 @@ class Bus:
subscribers.append(SUBSCRIBERS[window_id])
if encode_json:
data = dumps(data)
data = dumps(data, ensure_ascii=True)
for subscriber in subscribers:
logger.debug(" -> sending to subscriber: window_id '%s', user_id '%s'" % (subscriber.window_id, subscriber.user_id))
subscriber.send(data, binary=binary)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment