alasql 2.4.4 → 2.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/alasql-cli.js +1 -1
- package/dist/alasql-worker.js +2 -2
- package/dist/alasql-worker.min.js +1 -1
- package/dist/alasql.fs.js +233 -26
- package/dist/alasql.js +233 -26
- package/dist/alasql.min.js +84 -41
- package/dist/es5/alasql.fs.js +232 -25
- package/dist/es5/alasql.js +232 -25
- package/dist/es5/alasql.min.js +31 -2
- package/package.json +1 -1
package/dist/es5/alasql.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//! AlaSQL v2.4.
|
|
1
|
+
//! AlaSQL v2.4.5 | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
|
|
2
2
|
/*
|
|
3
3
|
@module alasql
|
|
4
|
-
@version 2.4.
|
|
4
|
+
@version 2.4.5
|
|
5
5
|
|
|
6
6
|
AlaSQL - JavaScript SQL database
|
|
7
7
|
© 2014-2023 Andrey Gershun & Mathias Wulff
|
|
@@ -844,15 +844,16 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
844
844
|
}
|
|
845
845
|
if (columns && columns.length > 0) {
|
|
846
846
|
columns.forEach(function(tcol) {
|
|
847
|
+
var escapedColumnId = escapeq(tcol.columnid);
|
|
847
848
|
if (joinstar && alasql.options.joinstar == "underscore") {
|
|
848
|
-
ss.push("'" + alias + "_" +
|
|
849
|
+
ss.push("'" + alias + "_" + escapedColumnId + "':p['" + alias + "']['" + escapedColumnId + "']");
|
|
849
850
|
} else if (joinstar && alasql.options.joinstar == "json") {
|
|
850
851
|
// ss.push('\''+alias+'_'+tcol.columnid+'\':p[\''+alias+'\'][\''+tcol.columnid+'\']');
|
|
851
|
-
sp += "r['" + alias + "']['" +
|
|
852
|
+
sp += "r['" + alias + "']['" + escapedColumnId + "']=p['" + alias + "']['" + escapedColumnId + "'];";
|
|
852
853
|
} else {
|
|
853
|
-
var value = "p['" + alias + "']['" +
|
|
854
|
+
var value = "p['" + alias + "']['" + escapedColumnId + "']";
|
|
854
855
|
if (!columnIds[tcol.columnid]) {
|
|
855
|
-
var key = "'" +
|
|
856
|
+
var key = "'" + escapedColumnId + "':";
|
|
856
857
|
ss.push(key + value);
|
|
857
858
|
columnIds[tcol.columnid] = {
|
|
858
859
|
id: ss.length - 1,
|
|
@@ -878,7 +879,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
878
879
|
});
|
|
879
880
|
} else {
|
|
880
881
|
// if column not exist, then copy all
|
|
881
|
-
sp += 'var w=p["' + alias + '"];for(var k in w){if(/^__proto__$/.test(k))Object.defineProperty(r,k,{writable:true,enumerable:true,configurable:true});r[k]=w[k]};';
|
|
882
|
+
sp += 'var w=p["' + escapeq(alias) + '"];for(var k in w){if(/^__proto__$/.test(k))Object.defineProperty(r,k,{writable:true,enumerable:true,configurable:true});r[k]=w[k]};';
|
|
882
883
|
query.dirtyColumns = true;
|
|
883
884
|
}
|
|
884
885
|
// }
|
|
@@ -1934,7 +1935,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
1934
1935
|
/**
|
|
1935
1936
|
Current version of alasql
|
|
1936
1937
|
@constant {string}
|
|
1937
|
-
*/ alasql.version = "2.4.
|
|
1938
|
+
*/ alasql.version = "2.4.5";
|
|
1938
1939
|
/**
|
|
1939
1940
|
Debug flag
|
|
1940
1941
|
@type {boolean}
|
|
@@ -49001,8 +49002,200 @@ _fetch = typeof fetch !== 'undefined' ? fetch : require('cross-fetch');
|
|
|
49001
49002
|
// My own parser here
|
|
49002
49003
|
}
|
|
49003
49004
|
*/ alasql.parse = function(sql) {
|
|
49004
|
-
|
|
49005
|
+
var ast = alasqlparser.parse(alasql.utils.uncomment(sql));
|
|
49006
|
+
checkSqlNames(ast);
|
|
49007
|
+
return ast;
|
|
49005
49008
|
};
|
|
49009
|
+
|
|
49010
|
+
/*
|
|
49011
|
+
A name from the SQL text is pasted into generated code between single quotes, so a name that
|
|
49012
|
+
holds a quote, a backslash or a line break would end the string and make the rest code
|
|
49013
|
+
(GHSA-67vj-hh8j-j94f). Such a name is refused here, once, after parsing. A name is a table,
|
|
49014
|
+
column, database, view, index, trigger or CTE name, a variable (and the keys of its path) and a
|
|
49015
|
+
table alias. The alias of a column in the select list is not a name: it is a key of the result,
|
|
49016
|
+
and the code that writes it escapes it. Strings, numbers, parameters, JavaScript and the keys
|
|
49017
|
+
of a JSON value are data, not names.
|
|
49018
|
+
*/
|
|
49019
|
+
var checkSqlNames = (function () {
|
|
49020
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
49021
|
+
var badName = /['\\\n\r\u2028\u2029]/;
|
|
49022
|
+
var nameKeys = {
|
|
49023
|
+
as: 1,
|
|
49024
|
+
columnid: 1,
|
|
49025
|
+
tableid: 1,
|
|
49026
|
+
databaseid: 1,
|
|
49027
|
+
viewid: 1,
|
|
49028
|
+
indexid: 1,
|
|
49029
|
+
trigger: 1,
|
|
49030
|
+
variable: 1,
|
|
49031
|
+
dropcolumn: 1,
|
|
49032
|
+
renamecolumn: 1,
|
|
49033
|
+
renameto: 1,
|
|
49034
|
+
to: 1,
|
|
49035
|
+
tocolumnid: 1,
|
|
49036
|
+
forcolumnid: 1,
|
|
49037
|
+
};
|
|
49038
|
+
var nameListKeys = {columns: 1, fkcolumns: 1, props: 1};
|
|
49039
|
+
|
|
49040
|
+
function checkName(name) {
|
|
49041
|
+
if (badName.test(name)) throw new SyntaxError('Not a valid name: ' + name);
|
|
49042
|
+
}
|
|
49043
|
+
|
|
49044
|
+
// ORDER BY: a name that equals an alias of the select list is that alias and is allowed (the code
|
|
49045
|
+
// escapes it), anything else is checked. (In this version a string in ORDER BY is a constant.)
|
|
49046
|
+
function checkOrder(columns, order) {
|
|
49047
|
+
var aliases = {};
|
|
49048
|
+
(columns || []).forEach(function (col) {
|
|
49049
|
+
if (col && typeof col.as === 'string') aliases[col.as] = true;
|
|
49050
|
+
});
|
|
49051
|
+
order.forEach(function (ord) {
|
|
49052
|
+
var e = ord && ord.expression;
|
|
49053
|
+
var name;
|
|
49054
|
+
if (e instanceof alasql.yy.Column && !e.tableid) name = e.columnid;
|
|
49055
|
+
if (typeof name === 'string') {
|
|
49056
|
+
if (!hasOwn.call(aliases, name)) checkName(name);
|
|
49057
|
+
return;
|
|
49058
|
+
}
|
|
49059
|
+
checkNames(ord, false, false);
|
|
49060
|
+
});
|
|
49061
|
+
}
|
|
49062
|
+
|
|
49063
|
+
// The alias of an entry of the select list, of SEARCH RETURNS and of CREATE GRAPH is a key of
|
|
49064
|
+
// the result or a variable and is allowed. The name of an entry of WITH is a table name; in a
|
|
49065
|
+
// graph item, name is data.
|
|
49066
|
+
function entryOf(node, key) {
|
|
49067
|
+
var yy = alasql.yy;
|
|
49068
|
+
if (
|
|
49069
|
+
(node instanceof yy.Select && key === 'columns') ||
|
|
49070
|
+
(node instanceof yy.CreateGraph && key === 'graph') ||
|
|
49071
|
+
(node.srchid === 'RETURN' && key === 'args')
|
|
49072
|
+
)
|
|
49073
|
+
return 'alias';
|
|
49074
|
+
if (node instanceof yy.WithSelect && key === 'withs') return 'with';
|
|
49075
|
+
return '';
|
|
49076
|
+
}
|
|
49077
|
+
|
|
49078
|
+
// Names that never reach generated code: they are used only at run time, as the key of a
|
|
49079
|
+
// database, a table, an index, a trigger or a variable, so the walk leaves them alone and such a
|
|
49080
|
+
// name keeps working. freeKeys are names of the node itself, freeChild are children whose own
|
|
49081
|
+
// names are free (what they hold is still walked), and skipChild are children that are not
|
|
49082
|
+
// walked at all (PIVOT and UNPIVOT work on the result and build no code).
|
|
49083
|
+
var varValueFree = false;
|
|
49084
|
+
var intoVarFree = false;
|
|
49085
|
+
var freeKeys = [
|
|
49086
|
+
['CreateIndex', {indexid: 1}],
|
|
49087
|
+
['DropIndex', {indexid: 1}],
|
|
49088
|
+
['Reindex', {indexid: 1}],
|
|
49089
|
+
['CreateTrigger', {trigger: 1}],
|
|
49090
|
+
['DropTrigger', {trigger: 1}],
|
|
49091
|
+
['CreateDatabase', {databaseid: 1, as: 1}],
|
|
49092
|
+
['AttachDatabase', {databaseid: 1, as: 1}],
|
|
49093
|
+
['DetachDatabase', {databaseid: 1}],
|
|
49094
|
+
['DropDatabase', {databaseid: 1}],
|
|
49095
|
+
['ShowTables', {databaseid: 1}],
|
|
49096
|
+
['ShowColumns', {databaseid: 1}],
|
|
49097
|
+
['ShowIndex', {databaseid: 1}],
|
|
49098
|
+
['ShowCreateTable', {databaseid: 1}],
|
|
49099
|
+
['AlterTable', {renameto: 1, renamecolumn: 1, dropcolumn: 1}],
|
|
49100
|
+
];
|
|
49101
|
+
var freeChild = [
|
|
49102
|
+
['CreateTable', {table: 1}],
|
|
49103
|
+
['DropTable', {tables: 1}],
|
|
49104
|
+
['TruncateTable', {table: 1}],
|
|
49105
|
+
['AlterTable', {table: 1}],
|
|
49106
|
+
['ShowColumns', {table: 1}],
|
|
49107
|
+
['ShowIndex', {table: 1}],
|
|
49108
|
+
['ShowCreateTable', {table: 1}],
|
|
49109
|
+
['CreateIndex', {table: 1}],
|
|
49110
|
+
['CreateTrigger', {table: 1}],
|
|
49111
|
+
['Declare', {declares: 1}],
|
|
49112
|
+
];
|
|
49113
|
+
var skipChild = [['Select', {pivot: 1, unpivot: 1}]];
|
|
49114
|
+
|
|
49115
|
+
function freeOf(list, node) {
|
|
49116
|
+
var yy = alasql.yy;
|
|
49117
|
+
for (var i = 0; i < list.length; i++) {
|
|
49118
|
+
var cls = yy[list[i][0]];
|
|
49119
|
+
if (cls && node instanceof cls) return list[i][1];
|
|
49120
|
+
}
|
|
49121
|
+
return null;
|
|
49122
|
+
}
|
|
49123
|
+
|
|
49124
|
+
// An @variable: an expression pastes it escaped where varValueFree is true, FROM @x pastes it
|
|
49125
|
+
// raw, and SELECT INTO @x pastes it raw where intoVarFree is false.
|
|
49126
|
+
function freeVar(node, key, entry) {
|
|
49127
|
+
var yy = alasql.yy;
|
|
49128
|
+
if (key !== 'variable' || !(node instanceof yy.VarValue)) return false;
|
|
49129
|
+
if (entry === 'source') return false;
|
|
49130
|
+
if (entry === 'into') return intoVarFree;
|
|
49131
|
+
return varValueFree;
|
|
49132
|
+
}
|
|
49133
|
+
|
|
49134
|
+
// SET @x = value without a path is a run-time assignment; with a path the name is pasted
|
|
49135
|
+
function freeSet(node, key) {
|
|
49136
|
+
var yy = alasql.yy;
|
|
49137
|
+
return key === 'variable' && yy.SetVariable && node instanceof yy.SetVariable && !(node.props && node.props.length);
|
|
49138
|
+
}
|
|
49139
|
+
|
|
49140
|
+
// data is true inside a JSON value, where a plain object is data and only a node is looked at.
|
|
49141
|
+
// entry is what entryOf says about the node as an entry of its parent, or 'free' when its own
|
|
49142
|
+
// names never reach generated code.
|
|
49143
|
+
function checkNames(node, data, entry) {
|
|
49144
|
+
if (node === null || typeof node !== 'object') return;
|
|
49145
|
+
var i;
|
|
49146
|
+
if (Array.isArray(node)) {
|
|
49147
|
+
for (i = 0; i < node.length; i++) checkNames(node[i], data, false);
|
|
49148
|
+
return;
|
|
49149
|
+
}
|
|
49150
|
+
var isNode = Object.getPrototypeOf(node) !== Object.prototype;
|
|
49151
|
+
if (data && !isNode) {
|
|
49152
|
+
for (i in node) if (hasOwn.call(node, i)) checkNames(node[i], true, false);
|
|
49153
|
+
return;
|
|
49154
|
+
}
|
|
49155
|
+
var yy = alasql.yy;
|
|
49156
|
+
if (node instanceof yy.Json) {
|
|
49157
|
+
checkNames(node.value, true, false);
|
|
49158
|
+
return;
|
|
49159
|
+
}
|
|
49160
|
+
var fk = freeOf(freeKeys, node);
|
|
49161
|
+
var fc = freeOf(freeChild, node);
|
|
49162
|
+
var sc = freeOf(skipChild, node);
|
|
49163
|
+
for (var key in node) {
|
|
49164
|
+
if (!hasOwn.call(node, key)) continue;
|
|
49165
|
+
var value = node[key];
|
|
49166
|
+
if (sc && sc[key] === 1) continue;
|
|
49167
|
+
if (key === 'order' && node instanceof yy.Select && Array.isArray(value)) {
|
|
49168
|
+
checkOrder(node.columns, value);
|
|
49169
|
+
continue;
|
|
49170
|
+
}
|
|
49171
|
+
// the column list of a WITH entry renames the result at run time
|
|
49172
|
+
var child = (fc && fc[key] === 1) || (entry === 'with' && key === 'columns') ? 'free' : '';
|
|
49173
|
+
if (!child && node instanceof yy.Select) child = key === 'from' ? 'source' : key === 'into' ? 'into' : '';
|
|
49174
|
+
if (typeof value === 'string') {
|
|
49175
|
+
if (entry === 'free' || (fk && fk[key] === 1) || freeSet(node, key) || freeVar(node, key, entry))
|
|
49176
|
+
continue;
|
|
49177
|
+
if (key === 'name' ? entry === 'with' : nameKeys[key] === 1 && !(entry === 'alias' && key === 'as'))
|
|
49178
|
+
checkName(value);
|
|
49179
|
+
} else if (value !== null && typeof value === 'object') {
|
|
49180
|
+
if (Array.isArray(value)) {
|
|
49181
|
+
for (i = 0; i < value.length; i++) {
|
|
49182
|
+
if (typeof value[i] === 'string') {
|
|
49183
|
+
if (nameListKeys[key] === 1 && entry !== 'free' && child !== 'free') checkName(value[i]);
|
|
49184
|
+
} else {
|
|
49185
|
+
checkNames(value[i], false, child || entryOf(node, key));
|
|
49186
|
+
}
|
|
49187
|
+
}
|
|
49188
|
+
} else {
|
|
49189
|
+
checkNames(value, false, child);
|
|
49190
|
+
}
|
|
49191
|
+
}
|
|
49192
|
+
}
|
|
49193
|
+
}
|
|
49194
|
+
|
|
49195
|
+
return function (ast) {
|
|
49196
|
+
checkNames(ast, false, false);
|
|
49197
|
+
};
|
|
49198
|
+
})();
|
|
49006
49199
|
/**
|
|
49007
49200
|
List of engines of external databases
|
|
49008
49201
|
@type {object}
|
|
@@ -50793,7 +50986,7 @@ _fetch = typeof fetch !== 'undefined' ? fetch : require('cross-fetch');
|
|
|
50793
50986
|
// Save data into parameters array
|
|
50794
50987
|
// like alasql('SELECT * INTO ? FROM ?',[outdata,srcdata]);
|
|
50795
50988
|
//
|
|
50796
|
-
query.intofns = "params['" + this.into.param + "'].push(r)";
|
|
50989
|
+
query.intofns = "params['" + escapeq(this.into.param) + "'].push(r)";
|
|
50797
50990
|
}
|
|
50798
50991
|
if (query.intofns) {
|
|
50799
50992
|
// Create intofn function
|
|
@@ -51023,7 +51216,7 @@ _fetch = typeof fetch !== 'undefined' ? fetch : require('cross-fetch');
|
|
|
51023
51216
|
return res;
|
|
51024
51217
|
};
|
|
51025
51218
|
} else if (_instanceof(tq, yy.ParamValue)) {
|
|
51026
|
-
ps = "var res = alasql.prepareFromData(params['" + tq.param + "']";
|
|
51219
|
+
ps = "var res = alasql.prepareFromData(params['" + escapeq(tq.param) + "']";
|
|
51027
51220
|
if (tq.array) ps += ",true";
|
|
51028
51221
|
ps += ");if(cb)res=cb(res,idx,query);return res";
|
|
51029
51222
|
source.datafn = new Function("query,params,cb,idx,alasql", ps);
|
|
@@ -51235,7 +51428,7 @@ _fetch = typeof fetch !== 'undefined' ? fetch : require('cross-fetch');
|
|
|
51235
51428
|
};
|
|
51236
51429
|
// source.data = ;
|
|
51237
51430
|
var jnparam = jn.param.param;
|
|
51238
|
-
ps = "var res=alasql.prepareFromData(params['" + jnparam + "']";
|
|
51431
|
+
ps = "var res=alasql.prepareFromData(params['" + escapeq(jnparam) + "']";
|
|
51239
51432
|
if (jn.array) ps += ",true";
|
|
51240
51433
|
ps += ");if(cb)res=cb(res, idx, query);return res";
|
|
51241
51434
|
source.datafn = new Function("query,params,cb,idx, alasql", ps);
|
|
@@ -51733,7 +51926,7 @@ _fetch = typeof fetch !== 'undefined' ? fetch : require('cross-fetch');
|
|
|
51733
51926
|
if (_instanceof(col, yy.Column)) {
|
|
51734
51927
|
if (col.columnid === "*") {
|
|
51735
51928
|
if (col.func) {
|
|
51736
|
-
sp += "r=params['" + col.param + "'](p['" + query.sources[0].alias + "'],p,params,alasql);";
|
|
51929
|
+
sp += "r=params['" + escapeq(col.param) + "'](p['" + query.sources[0].alias + "'],p,params,alasql);";
|
|
51737
51930
|
} else if (col.tableid) {
|
|
51738
51931
|
//Copy all
|
|
51739
51932
|
var ret = compileSelectStar(query, [
|
|
@@ -51767,10 +51960,10 @@ _fetch = typeof fetch !== 'undefined' ? fetch : require('cross-fetch');
|
|
|
51767
51960
|
// workaround for multisheet xlsx export with custom COLUMNS
|
|
51768
51961
|
var isMultisheetParam = params && params.length > 1 && Array.isArray(params[0]) && params[0].length >= 1 && params[0][0].hasOwnProperty("sheetid");
|
|
51769
51962
|
if (isMultisheetParam) {
|
|
51770
|
-
sp = 'var r={};var w=p["' + tbid + '"];' + "var cols=[" + _$self.columns.map(function(col) {
|
|
51963
|
+
sp = 'var r={};var w=p["' + escapeq(tbid) + '"];' + "var cols=[" + _$self.columns.map(function(col) {
|
|
51771
51964
|
return "'" + col.columnid + "'";
|
|
51772
51965
|
}).join(",") + "];var colas=[" + _$self.columns.map(function(col) {
|
|
51773
|
-
return "'" + (col.as || col.columnid) + "'";
|
|
51966
|
+
return "'" + escapeq(col.as || col.columnid) + "'";
|
|
51774
51967
|
}).join(",") + "];" + "for (var i=0;i<Object.keys(p['" + tbid + "']).length;i++)" + " for(var k=0;k<cols.length;k++){if (!r.hasOwnProperty(i)) r[i]={}; r[i][colas[k]]=w[i][cols[k]];}";
|
|
51775
51968
|
} else {
|
|
51776
51969
|
ss.push("'" + escapeq(col.as || col.columnid) + "':p['" + tbid + "']['" + col.columnid + "']");
|
|
@@ -51867,9 +52060,9 @@ _fetch = typeof fetch !== 'undefined' ? fetch : require('cross-fetch');
|
|
|
51867
52060
|
this.orderColumns.forEach(function(v, idx) {
|
|
51868
52061
|
var key = "$$$" + idx;
|
|
51869
52062
|
if (_instanceof(v, yy.Column) && query.xcolumns[v.columnid]) {
|
|
51870
|
-
s += "r['" + key + "']=r['" + v.columnid + "'];";
|
|
52063
|
+
s += "r['" + key + "']=r['" + escapeq(v.columnid) + "'];";
|
|
51871
52064
|
} else if (_instanceof(v, yy.ParamValue) && query.xcolumns[params[v.param]]) {
|
|
51872
|
-
s += "r['" + key + "']=r['" + params[v.param] + "'];";
|
|
52065
|
+
s += "r['" + key + "']=r['" + escapeq(params[v.param]) + "'];";
|
|
51873
52066
|
} else {
|
|
51874
52067
|
s += "r['" + key + "']=" + v.toJS("p", query.defaultTableid, query.defcols) + ";";
|
|
51875
52068
|
}
|
|
@@ -51945,7 +52138,7 @@ _fetch = typeof fetch !== 'undefined' ? fetch : require('cross-fetch');
|
|
|
51945
52138
|
}
|
|
51946
52139
|
query.groupColumns[colas] = col.nick;
|
|
51947
52140
|
// if(col.as) {
|
|
51948
|
-
s += "r['" + colas + "']=";
|
|
52141
|
+
s += "r['" + (col.as !== undefined ? escapeq(colas) : colas) + "']=";
|
|
51949
52142
|
// // } else {
|
|
51950
52143
|
// // s += 'r[\''+escapeq()+'\']=';
|
|
51951
52144
|
// // };
|
|
@@ -51968,14 +52161,14 @@ _fetch = typeof fetch !== 'undefined' ? fetch : require('cross-fetch');
|
|
|
51968
52161
|
var s = query.selectgfns;
|
|
51969
52162
|
_$self.columns.forEach(function(col) {
|
|
51970
52163
|
if (query.ingroup.indexOf(col.nick) > -1) {
|
|
51971
|
-
s += "r['" + (col.as
|
|
52164
|
+
s += "r['" + (col.as ? escapeq(col.as) : col.nick) + "']=g['" + col.nick + "'];";
|
|
51972
52165
|
}
|
|
51973
52166
|
});
|
|
51974
52167
|
if (this.orderColumns && this.orderColumns.length > 0) {
|
|
51975
52168
|
this.orderColumns.forEach(function(v, idx) {
|
|
51976
52169
|
var key = "$$$" + idx;
|
|
51977
52170
|
if (_instanceof(v, yy.Column) && query.groupColumns[v.columnid]) {
|
|
51978
|
-
s += "r['" + key + "']=r['" + v.columnid + "'];";
|
|
52171
|
+
s += "r['" + key + "']=r['" + escapeq(v.columnid) + "'];";
|
|
51979
52172
|
} else {
|
|
51980
52173
|
s += "r['" + key + "']=" + v.toJS("g", "") + ";";
|
|
51981
52174
|
}
|
|
@@ -52825,7 +53018,7 @@ if(false) {
|
|
|
52825
53018
|
// Expression to prevent error if object is empty (#344)
|
|
52826
53019
|
var ljs = "(" + leftJS() + "||{})";
|
|
52827
53020
|
if (typeof this.right === "string") {
|
|
52828
|
-
s = ljs + '["' + this.right + '"]';
|
|
53021
|
+
s = ljs + '["' + escapeq(this.right) + '"]';
|
|
52829
53022
|
} else if (typeof this.right === "number") {
|
|
52830
53023
|
s = ljs + "[" + this.right + "]";
|
|
52831
53024
|
} else if (_instanceof(this.right, yy.FuncValue)) {
|
|
@@ -52840,7 +53033,7 @@ if(false) {
|
|
|
52840
53033
|
}
|
|
52841
53034
|
if (this.op === "!") {
|
|
52842
53035
|
if (typeof this.right === "string") {
|
|
52843
|
-
s = "" + "alasql.databases[alasql.useid].objects[" + leftJS() + ']["' + this.right + '"]';
|
|
53036
|
+
s = "" + "alasql.databases[alasql.useid].objects[" + leftJS() + ']["' + escapeq(this.right) + '"]';
|
|
52844
53037
|
}
|
|
52845
53038
|
// TODO - add other cases
|
|
52846
53039
|
}
|
|
@@ -53176,7 +53369,7 @@ if(false) {
|
|
|
53176
53369
|
key: "toJS",
|
|
53177
53370
|
value: function toJS() {
|
|
53178
53371
|
if (typeof this.param === "string") {
|
|
53179
|
-
return "params['" + this.param + "']";
|
|
53372
|
+
return "params['" + escapeq(this.param) + "']";
|
|
53180
53373
|
}
|
|
53181
53374
|
return "params[" + this.param + "]";
|
|
53182
53375
|
}
|
|
@@ -54150,9 +54343,23 @@ if(false) {
|
|
|
54150
54343
|
}
|
|
54151
54344
|
return s;
|
|
54152
54345
|
};
|
|
54346
|
+
// A string value or key of a JSON value goes between double quotes in the generated code. A
|
|
54347
|
+
// backslash pair keeps its meaning; a lone backslash at the end, a double quote and a line break
|
|
54348
|
+
// are escaped, so the string cannot end early.
|
|
54349
|
+
function escapeJSONString(s) {
|
|
54350
|
+
return s.replace(/\\[\s\S]|\\$|"|\n|\r|\u2028|\u2029/g, function (c) {
|
|
54351
|
+
if (c.length === 2) return c;
|
|
54352
|
+
if (c === '\\') return '\\\\';
|
|
54353
|
+
if (c === '"') return '\\"';
|
|
54354
|
+
if (c === '\n') return '\\n';
|
|
54355
|
+
if (c === '\r') return '\\r';
|
|
54356
|
+
return c === '\u2028' ? '\\u2028' : '\\u2029';
|
|
54357
|
+
});
|
|
54358
|
+
}
|
|
54359
|
+
|
|
54153
54360
|
function JSONtoJS(obj, context, tableid, defcols) {
|
|
54154
54361
|
var s = "";
|
|
54155
|
-
if (typeof obj == "string") s = '"' + obj + '"';
|
|
54362
|
+
if (typeof obj == "string") s = '"' + escapeJSONString(obj) + '"';
|
|
54156
54363
|
else if (typeof obj == "number") s = "(" + obj + ")";
|
|
54157
54364
|
else if (typeof obj == "boolean") s = obj;
|
|
54158
54365
|
else if (typeof obj == "object") {
|
|
@@ -54166,7 +54373,7 @@ if(false) {
|
|
|
54166
54373
|
var ss = [];
|
|
54167
54374
|
for(var k in obj){
|
|
54168
54375
|
var s1 = "";
|
|
54169
|
-
if (typeof k == "string") s1 += '"' + k + '"';
|
|
54376
|
+
if (typeof k == "string") s1 += '"' + escapeJSONString(k) + '"';
|
|
54170
54377
|
else if (typeof k == "number") s1 += k;
|
|
54171
54378
|
else if (typeof k == "boolean") s1 += k;
|
|
54172
54379
|
else {
|