From 95b7c52be4b047a18e7e80713492359495386616 Mon Sep 17 00:00:00 2001 From: Taka Date: Sat, 13 Feb 2021 15:04:28 +1100 Subject: [PATCH] Fixed an encoding problem when uploading scenarios to the ASL Scenario Archive. --- vasl_templates/webapp/static/scenario-upload.js | 6 ++++-- vasl_templates/webapp/static/utils.js | 12 +++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/vasl_templates/webapp/static/scenario-upload.js b/vasl_templates/webapp/static/scenario-upload.js index 777932c..74b5573 100644 --- a/vasl_templates/webapp/static/scenario-upload.js +++ b/vasl_templates/webapp/static/scenario-upload.js @@ -139,7 +139,7 @@ window.uploadScenario = function() { ) ; } - // shpw the upload dialog + // show the upload dialog $( "#scenario-upload-dialog" ).dialog( { title: "Upload to the ASL Scenario Archive", dialogClass: "scenario-upload", @@ -274,8 +274,10 @@ function uploadFiles( asaScenarioId ) // prepare the upload var formData = new FormData() ; + var vtSetupJson = JSON.stringify( vtSetup, null, 4 ) ; + var vtSetupJsonUTF8 = (new TextEncoder()).encode( vtSetupJson ) ; formData.append( "vt_setup", - makeBlob( JSON.stringify( vtSetup, null, 4 ), "application/json" ), + makeBlob( vtSetupJsonUTF8, "application/json" ), prefix + "|" + "scenario.json" ) ; if ( gVsavData ) { diff --git a/vasl_templates/webapp/static/utils.js b/vasl_templates/webapp/static/utils.js index 84c0dd0..067b756 100644 --- a/vasl_templates/webapp/static/utils.js +++ b/vasl_templates/webapp/static/utils.js @@ -608,9 +608,15 @@ function stopEvent( evt ) function makeBlob( data, mimeType ) { // create a Blob from a binary string - var bytes = new Uint8Array( data.length ) ; - for ( var i=0 ; i < data.length ; ++i ) - bytes[i] = data.charCodeAt( i ) ; + var bytes ; + if ( typeof data === "object" ) + bytes = data ; // i.e. output from TextEncoder.encode() + else if ( typeof data === "string" ) { + bytes = new Uint8Array( data.length ) ; + for ( var i=0 ; i < data.length ; ++i ) + bytes[i] = data.charCodeAt( i ) ; + } else + return null ; return new Blob( [bytes], { type: mimeType || "application/octet-stream" } ) ;