From d488ea7f812bf8c5b8ecd3b987f79c1a2c3bbd21 Mon Sep 17 00:00:00 2001 From: JannisX11 Date: Tue, 19 Jan 2021 17:59:17 +0100 Subject: [PATCH] Escape keys in JSON exporter --- js/io/io.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/js/io/io.js b/js/io/io.js index 44665a91..ff65a44a 100644 --- a/js/io/io.js +++ b/js/io/io.js @@ -356,7 +356,6 @@ function uploadSketchfabModel() { } //Json function compileJSON(object, options) { - var output = '' if (typeof options !== 'object') options = {} function newLine(tabs) { if (options.small === true) {return '';} @@ -366,11 +365,14 @@ function compileJSON(object, options) { } return s; } + function escape(string) { + return string.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n|\r\n/g, '\\n').replace(/\t/g, '\\t') + } function handleVar(o, tabs) { var out = '' if (typeof o === 'string') { //String - out += '"' + o.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n|\r\n/g, '\\n').replace(/\t/g, '\\t') + '"' + out += '"' + escape(o) + '"' } else if (typeof o === 'boolean') { //Boolean out += (o ? 'true' : 'false') @@ -408,7 +410,7 @@ function compileJSON(object, options) { if (compiled) { if (has_content) {out += ',' + (breaks || options.small?'':' ')} if (breaks) {out += newLine(tabs)} - out += '"' + key + '":' + (options.small === true ? '' : ' ') + out += '"' + escape(key) + '":' + (options.small === true ? '' : ' ') out += compiled has_content = true }