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.
This commit is contained in:
James Allen 2017-04-10 12:03:39 +01:00
parent 477278eea5
commit f6bd949f01
2 changed files with 10 additions and 4 deletions

View file

@ -105,10 +105,16 @@ block requirejs
//- We need to do .replace(/\//g, '\\/') do that '</script>' -> '<\/script>' //- We need to do .replace(/\//g, '\\/') do that '</script>' -> '<\/script>'
//- and doesn't prematurely end the script tag. //- 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'). script(type='text/javascript').
window.project_id = "!{project_id}"; window.project_id = "!{project_id}";
window.userSettings = !{JSON.stringify(userSettings).replace(/\//g, '\\/')}; var data = JSON.parse($("#data").text());
window.user = !{JSON.stringify(user).replace(/\//g, '\\/')}; window.userSettings = data.userSettings;
window.user = data.user;
window.csrfToken = "!{csrfToken}"; window.csrfToken = "!{csrfToken}";
window.anonymous = #{anonymous}; window.anonymous = #{anonymous};
window.maxDocLength = #{maxDocLength}; window.maxDocLength = #{maxDocLength};

View file

@ -146,7 +146,7 @@ define [], () ->
else else
@ide.socket.disconnect() @ide.socket.disconnect()
@ide.showGenericMessageModal("Something went wrong connecting", """ @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: () -> joinProject: () ->
@ -157,7 +157,7 @@ define [], () ->
@ide.socket.emit 'joinProject', { @ide.socket.emit 'joinProject', {
project_id: @ide.project_id project_id: @ide.project_id
}, (err, project, permissionsLevel, protocolVersion) => }, (err, project, permissionsLevel, protocolVersion) =>
if err? if err? or !project?
return @reportConnectionError(err) return @reportConnectionError(err)
if @$scope.protocolVersion? and @$scope.protocolVersion != protocolVersion if @$scope.protocolVersion? and @$scope.protocolVersion != protocolVersion