mirror of
https://github.com/JannisX11/blockbench.git
synced 2025-01-30 15:42:42 +08:00
Escape keys in JSON exporter
This commit is contained in:
parent
f182d199bc
commit
d488ea7f81
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user