From f6bd949f01bd048ff06b1eb43fe5260f737a52c5 Mon Sep 17 00:00:00 2001 From: James Allen Date: Mon, 10 Apr 2017 12:03:39 +0100 Subject: [PATCH] Error if no project returned from joinProject socket.io seems to choke on the unicode project name and just return undefined when it fails to parse the JSON. I've improved the escaping of the user data on HTML load, but reporting an error is the best we can easily do on joinProject via websockets. --- services/web/app/views/project/editor.pug | 10 ++++++++-- .../coffee/ide/connection/ConnectionManager.coffee | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/services/web/app/views/project/editor.pug b/services/web/app/views/project/editor.pug index eb265b5055..5b6137738b 100644 --- a/services/web/app/views/project/editor.pug +++ b/services/web/app/views/project/editor.pug @@ -105,10 +105,16 @@ block requirejs //- We need to do .replace(/\//g, '\\/') do that '' -> '<\/script>' //- and doesn't prematurely end the script tag. + script#data(type="application/json"). + !{JSON.stringify({userSettings: userSettings, user: user}).replace(/\//g, '\\/')} + + script(type="text/javascript"). + window.data = JSON.parse($("#data").text()); script(type='text/javascript'). window.project_id = "!{project_id}"; - window.userSettings = !{JSON.stringify(userSettings).replace(/\//g, '\\/')}; - window.user = !{JSON.stringify(user).replace(/\//g, '\\/')}; + var data = JSON.parse($("#data").text()); + window.userSettings = data.userSettings; + window.user = data.user; window.csrfToken = "!{csrfToken}"; window.anonymous = #{anonymous}; window.maxDocLength = #{maxDocLength}; diff --git a/services/web/public/coffee/ide/connection/ConnectionManager.coffee b/services/web/public/coffee/ide/connection/ConnectionManager.coffee index a8696fc999..134d0cb980 100644 --- a/services/web/public/coffee/ide/connection/ConnectionManager.coffee +++ b/services/web/public/coffee/ide/connection/ConnectionManager.coffee @@ -146,7 +146,7 @@ define [], () -> else @ide.socket.disconnect() @ide.showGenericMessageModal("Something went wrong connecting", """ - Something went wrong connecting to your project. Please refresh is this continues to happen. + Something went wrong connecting to your project. Please refresh if this continues to happen. """) joinProject: () -> @@ -157,7 +157,7 @@ define [], () -> @ide.socket.emit 'joinProject', { project_id: @ide.project_id }, (err, project, permissionsLevel, protocolVersion) => - if err? + if err? or !project? return @reportConnectionError(err) if @$scope.protocolVersion? and @$scope.protocolVersion != protocolVersion