alasql 0.7.2 → 0.7.4
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 +240 -33
- package/dist/alasql.js +240 -33
- package/dist/alasql.min.js +37 -2
- package/package.json +1 -1
package/dist/alasql.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//! AlaSQL v0.7.
|
|
1
|
+
//! AlaSQL v0.7.4 | © 2014-2018 Andrey Gershun & Mathias Rangel Wulff | License: MIT
|
|
2
2
|
/*
|
|
3
3
|
@module alasql
|
|
4
|
-
@version 0.7.
|
|
4
|
+
@version 0.7.4
|
|
5
5
|
|
|
6
6
|
AlaSQL - JavaScript SQL database
|
|
7
7
|
© 2014-2016 Andrey Gershun & Mathias Rangel Wulff
|
|
@@ -142,7 +142,7 @@ var alasql = function(sql, params, cb, scope) {
|
|
|
142
142
|
Current version of alasql
|
|
143
143
|
@constant {string}
|
|
144
144
|
*/
|
|
145
|
-
alasql.version = '0.7.
|
|
145
|
+
alasql.version = '0.7.4';
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
148
|
Debug flag
|
|
@@ -2492,7 +2492,7 @@ next:function () {
|
|
|
2492
2492
|
|
|
2493
2493
|
// return next match that has a token
|
|
2494
2494
|
lex:function lex () {
|
|
2495
|
-
var r = this.next();
|
|
2495
|
+
var r = this.next();if(r&&/^(N?['"]__proto__['"]|\[__proto__\]|`__proto__`|__proto__)$/i.test(this.yytext))throw new Error("__proto__ is not allowed");
|
|
2496
2496
|
if (r) {
|
|
2497
2497
|
return r;
|
|
2498
2498
|
} else {
|
|
@@ -4440,9 +4440,201 @@ alasql.parser.parseError = function (str, hash) {
|
|
|
4440
4440
|
}
|
|
4441
4441
|
*/
|
|
4442
4442
|
alasql.parse = function (sql) {
|
|
4443
|
-
|
|
4443
|
+
var ast = alasqlparser.parse(alasql.utils.uncomment(sql));
|
|
4444
|
+
checkSqlNames(ast);
|
|
4445
|
+
return ast;
|
|
4444
4446
|
};
|
|
4445
4447
|
|
|
4448
|
+
/*
|
|
4449
|
+
A name from the SQL text is pasted into generated code between single quotes, so a name that
|
|
4450
|
+
holds a quote, a backslash or a line break would end the string and make the rest code
|
|
4451
|
+
(GHSA-67vj-hh8j-j94f). Such a name is refused here, once, after parsing. A name is a table,
|
|
4452
|
+
column, database, view, index, trigger or CTE name, a variable (and the keys of its path) and a
|
|
4453
|
+
table alias. The alias of a column in the select list is not a name: it is a key of the result,
|
|
4454
|
+
and the code that writes it escapes it. Strings, numbers, parameters, JavaScript and the keys
|
|
4455
|
+
of a JSON value are data, not names.
|
|
4456
|
+
*/
|
|
4457
|
+
var checkSqlNames = (function () {
|
|
4458
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
4459
|
+
var badName = /['\\\n\r\u2028\u2029]/;
|
|
4460
|
+
var nameKeys = {
|
|
4461
|
+
as: 1,
|
|
4462
|
+
columnid: 1,
|
|
4463
|
+
tableid: 1,
|
|
4464
|
+
databaseid: 1,
|
|
4465
|
+
viewid: 1,
|
|
4466
|
+
indexid: 1,
|
|
4467
|
+
trigger: 1,
|
|
4468
|
+
variable: 1,
|
|
4469
|
+
dropcolumn: 1,
|
|
4470
|
+
renamecolumn: 1,
|
|
4471
|
+
renameto: 1,
|
|
4472
|
+
to: 1,
|
|
4473
|
+
tocolumnid: 1,
|
|
4474
|
+
forcolumnid: 1,
|
|
4475
|
+
};
|
|
4476
|
+
var nameListKeys = {columns: 1, fkcolumns: 1, props: 1};
|
|
4477
|
+
|
|
4478
|
+
function checkName(name) {
|
|
4479
|
+
if (badName.test(name)) throw new SyntaxError('Not a valid name: ' + name);
|
|
4480
|
+
}
|
|
4481
|
+
|
|
4482
|
+
// ORDER BY: a name that equals an alias of the select list is that alias and is allowed (the code
|
|
4483
|
+
// escapes it), anything else is checked. (In this version a string in ORDER BY is a constant.)
|
|
4484
|
+
function checkOrder(columns, order) {
|
|
4485
|
+
var aliases = {};
|
|
4486
|
+
(columns || []).forEach(function (col) {
|
|
4487
|
+
if (col && typeof col.as === 'string') aliases[col.as] = true;
|
|
4488
|
+
});
|
|
4489
|
+
order.forEach(function (ord) {
|
|
4490
|
+
var e = ord && ord.expression;
|
|
4491
|
+
var name;
|
|
4492
|
+
if (e instanceof alasql.yy.Column && !e.tableid) name = e.columnid;
|
|
4493
|
+
if (typeof name === 'string') {
|
|
4494
|
+
if (!hasOwn.call(aliases, name)) checkName(name);
|
|
4495
|
+
return;
|
|
4496
|
+
}
|
|
4497
|
+
checkNames(ord, false, false);
|
|
4498
|
+
});
|
|
4499
|
+
}
|
|
4500
|
+
|
|
4501
|
+
// The alias of an entry of the select list, of SEARCH RETURNS and of CREATE GRAPH is a key of
|
|
4502
|
+
// the result or a variable and is allowed. The name of an entry of WITH is a table name; in a
|
|
4503
|
+
// graph item, name is data.
|
|
4504
|
+
function entryOf(node, key) {
|
|
4505
|
+
var yy = alasql.yy;
|
|
4506
|
+
if (
|
|
4507
|
+
(node instanceof yy.Select && key === 'columns') ||
|
|
4508
|
+
(node instanceof yy.CreateGraph && key === 'graph') ||
|
|
4509
|
+
(node.srchid === 'RETURN' && key === 'args')
|
|
4510
|
+
)
|
|
4511
|
+
return 'alias';
|
|
4512
|
+
if (node instanceof yy.WithSelect && key === 'withs') return 'with';
|
|
4513
|
+
return '';
|
|
4514
|
+
}
|
|
4515
|
+
|
|
4516
|
+
// Names that never reach generated code: they are used only at run time, as the key of a
|
|
4517
|
+
// database, a table, an index, a trigger or a variable, so the walk leaves them alone and such a
|
|
4518
|
+
// name keeps working. freeKeys are names of the node itself, freeChild are children whose own
|
|
4519
|
+
// names are free (what they hold is still walked), and skipChild are children that are not
|
|
4520
|
+
// walked at all (PIVOT and UNPIVOT work on the result and build no code).
|
|
4521
|
+
var varValueFree = false;
|
|
4522
|
+
var intoVarFree = false;
|
|
4523
|
+
var freeKeys = [
|
|
4524
|
+
['CreateIndex', {indexid: 1}],
|
|
4525
|
+
['DropIndex', {indexid: 1}],
|
|
4526
|
+
['Reindex', {indexid: 1}],
|
|
4527
|
+
['CreateTrigger', {trigger: 1}],
|
|
4528
|
+
['DropTrigger', {trigger: 1}],
|
|
4529
|
+
['CreateDatabase', {databaseid: 1, as: 1}],
|
|
4530
|
+
['AttachDatabase', {databaseid: 1, as: 1}],
|
|
4531
|
+
['DetachDatabase', {databaseid: 1}],
|
|
4532
|
+
['DropDatabase', {databaseid: 1}],
|
|
4533
|
+
['ShowTables', {databaseid: 1}],
|
|
4534
|
+
['ShowColumns', {databaseid: 1}],
|
|
4535
|
+
['ShowIndex', {databaseid: 1}],
|
|
4536
|
+
['ShowCreateTable', {databaseid: 1}],
|
|
4537
|
+
['AlterTable', {renameto: 1, renamecolumn: 1, dropcolumn: 1}],
|
|
4538
|
+
];
|
|
4539
|
+
var freeChild = [
|
|
4540
|
+
['CreateTable', {table: 1}],
|
|
4541
|
+
['DropTable', {tables: 1}],
|
|
4542
|
+
['TruncateTable', {table: 1}],
|
|
4543
|
+
['AlterTable', {table: 1}],
|
|
4544
|
+
['ShowColumns', {table: 1}],
|
|
4545
|
+
['ShowIndex', {table: 1}],
|
|
4546
|
+
['ShowCreateTable', {table: 1}],
|
|
4547
|
+
['CreateIndex', {table: 1}],
|
|
4548
|
+
['CreateTrigger', {table: 1}],
|
|
4549
|
+
['Declare', {declares: 1}],
|
|
4550
|
+
];
|
|
4551
|
+
var skipChild = [['Select', {pivot: 1, unpivot: 1}]];
|
|
4552
|
+
|
|
4553
|
+
function freeOf(list, node) {
|
|
4554
|
+
var yy = alasql.yy;
|
|
4555
|
+
for (var i = 0; i < list.length; i++) {
|
|
4556
|
+
var cls = yy[list[i][0]];
|
|
4557
|
+
if (cls && node instanceof cls) return list[i][1];
|
|
4558
|
+
}
|
|
4559
|
+
return null;
|
|
4560
|
+
}
|
|
4561
|
+
|
|
4562
|
+
// An @variable: an expression pastes it escaped where varValueFree is true, FROM @x pastes it
|
|
4563
|
+
// raw, and SELECT INTO @x pastes it raw where intoVarFree is false.
|
|
4564
|
+
function freeVar(node, key, entry) {
|
|
4565
|
+
var yy = alasql.yy;
|
|
4566
|
+
if (key !== 'variable' || !(node instanceof yy.VarValue)) return false;
|
|
4567
|
+
if (entry === 'source') return false;
|
|
4568
|
+
if (entry === 'into') return intoVarFree;
|
|
4569
|
+
return varValueFree;
|
|
4570
|
+
}
|
|
4571
|
+
|
|
4572
|
+
// SET @x = value without a path is a run-time assignment; with a path the name is pasted
|
|
4573
|
+
function freeSet(node, key) {
|
|
4574
|
+
var yy = alasql.yy;
|
|
4575
|
+
return key === 'variable' && yy.SetVariable && node instanceof yy.SetVariable && !(node.props && node.props.length);
|
|
4576
|
+
}
|
|
4577
|
+
|
|
4578
|
+
// data is true inside a JSON value, where a plain object is data and only a node is looked at.
|
|
4579
|
+
// entry is what entryOf says about the node as an entry of its parent, or 'free' when its own
|
|
4580
|
+
// names never reach generated code.
|
|
4581
|
+
function checkNames(node, data, entry) {
|
|
4582
|
+
if (node === null || typeof node !== 'object') return;
|
|
4583
|
+
var i;
|
|
4584
|
+
if (Array.isArray(node)) {
|
|
4585
|
+
for (i = 0; i < node.length; i++) checkNames(node[i], data, false);
|
|
4586
|
+
return;
|
|
4587
|
+
}
|
|
4588
|
+
var isNode = Object.getPrototypeOf(node) !== Object.prototype;
|
|
4589
|
+
if (data && !isNode) {
|
|
4590
|
+
for (i in node) if (hasOwn.call(node, i)) checkNames(node[i], true, false);
|
|
4591
|
+
return;
|
|
4592
|
+
}
|
|
4593
|
+
var yy = alasql.yy;
|
|
4594
|
+
if (node instanceof yy.Json) {
|
|
4595
|
+
checkNames(node.value, true, false);
|
|
4596
|
+
return;
|
|
4597
|
+
}
|
|
4598
|
+
var fk = freeOf(freeKeys, node);
|
|
4599
|
+
var fc = freeOf(freeChild, node);
|
|
4600
|
+
var sc = freeOf(skipChild, node);
|
|
4601
|
+
for (var key in node) {
|
|
4602
|
+
if (!hasOwn.call(node, key)) continue;
|
|
4603
|
+
var value = node[key];
|
|
4604
|
+
if (sc && sc[key] === 1) continue;
|
|
4605
|
+
if (key === 'order' && node instanceof yy.Select && Array.isArray(value)) {
|
|
4606
|
+
checkOrder(node.columns, value);
|
|
4607
|
+
continue;
|
|
4608
|
+
}
|
|
4609
|
+
// the column list of a WITH entry renames the result at run time
|
|
4610
|
+
var child = (fc && fc[key] === 1) || (entry === 'with' && key === 'columns') ? 'free' : '';
|
|
4611
|
+
if (!child && node instanceof yy.Select) child = key === 'from' ? 'source' : key === 'into' ? 'into' : '';
|
|
4612
|
+
if (typeof value === 'string') {
|
|
4613
|
+
if (entry === 'free' || (fk && fk[key] === 1) || freeSet(node, key) || freeVar(node, key, entry))
|
|
4614
|
+
continue;
|
|
4615
|
+
if (key === 'name' ? entry === 'with' : nameKeys[key] === 1 && !(entry === 'alias' && key === 'as'))
|
|
4616
|
+
checkName(value);
|
|
4617
|
+
} else if (value !== null && typeof value === 'object') {
|
|
4618
|
+
if (Array.isArray(value)) {
|
|
4619
|
+
for (i = 0; i < value.length; i++) {
|
|
4620
|
+
if (typeof value[i] === 'string') {
|
|
4621
|
+
if (nameListKeys[key] === 1 && entry !== 'free' && child !== 'free') checkName(value[i]);
|
|
4622
|
+
} else {
|
|
4623
|
+
checkNames(value[i], false, child || entryOf(node, key));
|
|
4624
|
+
}
|
|
4625
|
+
}
|
|
4626
|
+
} else {
|
|
4627
|
+
checkNames(value, false, child);
|
|
4628
|
+
}
|
|
4629
|
+
}
|
|
4630
|
+
}
|
|
4631
|
+
}
|
|
4632
|
+
|
|
4633
|
+
return function (ast) {
|
|
4634
|
+
checkNames(ast, false, false);
|
|
4635
|
+
};
|
|
4636
|
+
})();
|
|
4637
|
+
|
|
4446
4638
|
/**
|
|
4447
4639
|
List of engines of external databases
|
|
4448
4640
|
@type {object}
|
|
@@ -6935,7 +7127,7 @@ function queryfn3(query) {
|
|
|
6935
7127
|
|
|
6936
7128
|
// Prepare variables
|
|
6937
7129
|
query.data = [];
|
|
6938
|
-
query.xgroups
|
|
7130
|
+
query.xgroups=Object.create(null);
|
|
6939
7131
|
query.groups = [];
|
|
6940
7132
|
|
|
6941
7133
|
// Level of Joins
|
|
@@ -7976,7 +8168,7 @@ yy.Select.prototype.compile = function (databaseid, params) {
|
|
|
7976
8168
|
// Save data into parameters array
|
|
7977
8169
|
// like alasql('SELECT * INTO ? FROM ?',[outdata,srcdata]);
|
|
7978
8170
|
//
|
|
7979
|
-
query.intofns = "params['" + this.into.param + "'].push(r)";
|
|
8171
|
+
query.intofns = "params['" + escapeq(this.into.param) + "'].push(r)";
|
|
7980
8172
|
}
|
|
7981
8173
|
|
|
7982
8174
|
if (query.intofns) {
|
|
@@ -8381,7 +8573,7 @@ yy.Select.prototype.compileFrom = function (query) {
|
|
|
8381
8573
|
return res;
|
|
8382
8574
|
};
|
|
8383
8575
|
} else if (tq instanceof yy.ParamValue) {
|
|
8384
|
-
ps = "var res = alasql.prepareFromData(params['" + tq.param + "']";
|
|
8576
|
+
ps = "var res = alasql.prepareFromData(params['" + escapeq(tq.param) + "']";
|
|
8385
8577
|
|
|
8386
8578
|
if (tq.array) ps += ',true';
|
|
8387
8579
|
ps += ');if(cb)res=cb(res,idx,query);return res';
|
|
@@ -8630,7 +8822,7 @@ yy.Select.prototype.compileJoins = function (query) {
|
|
|
8630
8822
|
// source.data = ;
|
|
8631
8823
|
var jnparam = jn.param.param;
|
|
8632
8824
|
|
|
8633
|
-
ps = "var res=alasql.prepareFromData(params['" + jnparam + "']";
|
|
8825
|
+
ps = "var res=alasql.prepareFromData(params['" + escapeq(jnparam) + "']";
|
|
8634
8826
|
if (jn.array) ps += ',true';
|
|
8635
8827
|
ps += ');if(cb)res=cb(res, idx, query);return res';
|
|
8636
8828
|
|
|
@@ -9329,9 +9521,10 @@ function compileSelectStar(query, aliases, joinstar) {
|
|
|
9329
9521
|
|
|
9330
9522
|
if (columns && columns.length > 0) {
|
|
9331
9523
|
columns.forEach(function (tcol) {
|
|
9524
|
+
var escapedColumnId = escapeq(tcol.columnid);
|
|
9332
9525
|
if (joinstar && alasql.options.joinstar == 'underscore') {
|
|
9333
9526
|
ss.push(
|
|
9334
|
-
"'" + alias + '_' +
|
|
9527
|
+
"'" + alias + '_' + escapedColumnId + "':p['" + alias + "']['" + escapedColumnId + "']"
|
|
9335
9528
|
);
|
|
9336
9529
|
} else if (joinstar && alasql.options.joinstar == 'json') {
|
|
9337
9530
|
// ss.push('\''+alias+'_'+tcol.columnid+'\':p[\''+alias+'\'][\''+tcol.columnid+'\']');
|
|
@@ -9339,16 +9532,16 @@ function compileSelectStar(query, aliases, joinstar) {
|
|
|
9339
9532
|
"r['" +
|
|
9340
9533
|
alias +
|
|
9341
9534
|
"']['" +
|
|
9342
|
-
|
|
9535
|
+
escapedColumnId +
|
|
9343
9536
|
"']=p['" +
|
|
9344
9537
|
alias +
|
|
9345
9538
|
"']['" +
|
|
9346
|
-
|
|
9539
|
+
escapedColumnId +
|
|
9347
9540
|
"'];";
|
|
9348
9541
|
} else {
|
|
9349
|
-
var value = "p['" + alias + "']['" +
|
|
9542
|
+
var value = "p['" + alias + "']['" + escapedColumnId + "']";
|
|
9350
9543
|
if (!columnIds[tcol.columnid]) {
|
|
9351
|
-
var key = "'" +
|
|
9544
|
+
var key = "'" + escapedColumnId + "':";
|
|
9352
9545
|
ss.push(key + value);
|
|
9353
9546
|
columnIds[tcol.columnid] = {
|
|
9354
9547
|
id: ss.length - 1,
|
|
@@ -9379,7 +9572,7 @@ function compileSelectStar(query, aliases, joinstar) {
|
|
|
9379
9572
|
} else {
|
|
9380
9573
|
|
|
9381
9574
|
// if column not exist, then copy all
|
|
9382
|
-
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]};';
|
|
9575
|
+
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]};';
|
|
9383
9576
|
|
|
9384
9577
|
query.dirtyColumns = true;
|
|
9385
9578
|
}
|
|
@@ -9406,7 +9599,7 @@ yy.Select.prototype.compileSelect1 = function (query, params) {
|
|
|
9406
9599
|
if (col.columnid === '*') {
|
|
9407
9600
|
if (col.func) {
|
|
9408
9601
|
sp +=
|
|
9409
|
-
"r=params['" + col.param + "'](p['" + query.sources[0].alias + "'],p,params,alasql);";
|
|
9602
|
+
"r=params['" + escapeq(col.param) + "'](p['" + query.sources[0].alias + "'],p,params,alasql);";
|
|
9410
9603
|
} else if (col.tableid) {
|
|
9411
9604
|
//Copy all
|
|
9412
9605
|
var ret = compileSelectStar(query, [col.tableid], false);
|
|
@@ -9458,7 +9651,7 @@ yy.Select.prototype.compileSelect1 = function (query, params) {
|
|
|
9458
9651
|
if (isMultisheetParam) {
|
|
9459
9652
|
sp =
|
|
9460
9653
|
'var r={};var w=p["' +
|
|
9461
|
-
tbid +
|
|
9654
|
+
escapeq(tbid) +
|
|
9462
9655
|
'"];' +
|
|
9463
9656
|
'var cols=[' +
|
|
9464
9657
|
self.columns
|
|
@@ -9469,7 +9662,7 @@ yy.Select.prototype.compileSelect1 = function (query, params) {
|
|
|
9469
9662
|
'];var colas=[' +
|
|
9470
9663
|
self.columns
|
|
9471
9664
|
.map(function (col) {
|
|
9472
|
-
return "'" + (col.as || col.columnid) + "'";
|
|
9665
|
+
return "'" + escapeq(col.as || col.columnid) + "'";
|
|
9473
9666
|
})
|
|
9474
9667
|
.join(',') +
|
|
9475
9668
|
'];' +
|
|
@@ -9632,9 +9825,9 @@ yy.Select.prototype.compileSelect2 = function (query, params) {
|
|
|
9632
9825
|
this.orderColumns.forEach(function (v, idx) {
|
|
9633
9826
|
var key = '$$$' + idx;
|
|
9634
9827
|
if (v instanceof yy.Column && query.xcolumns[v.columnid]) {
|
|
9635
|
-
s += "r['" + key + "']=r['" + v.columnid + "'];";
|
|
9828
|
+
s += "r['" + key + "']=r['" + escapeq(v.columnid) + "'];";
|
|
9636
9829
|
} else if (v instanceof yy.ParamValue && query.xcolumns[params[v.param]]) {
|
|
9637
|
-
s += "r['" + key + "']=r['" + params[v.param] + "'];";
|
|
9830
|
+
s += "r['" + key + "']=r['" + escapeq(params[v.param]) + "'];";
|
|
9638
9831
|
} else {
|
|
9639
9832
|
s += "r['" + key + "']=" + v.toJS('p', query.defaultTableid, query.defcols) + ';';
|
|
9640
9833
|
}
|
|
@@ -9727,7 +9920,7 @@ yy.Select.prototype.compileSelectGroup1 = function (query) {
|
|
|
9727
9920
|
query.groupColumns[colas] = col.nick;
|
|
9728
9921
|
|
|
9729
9922
|
// if(col.as) {
|
|
9730
|
-
s += "r['" + colas + "']=";
|
|
9923
|
+
s += "r['" + (col.as !== undefined ? escapeq(colas) : colas) + "']=";
|
|
9731
9924
|
// // } else {
|
|
9732
9925
|
// // s += 'r[\''+escapeq()+'\']=';
|
|
9733
9926
|
// // };
|
|
@@ -9754,7 +9947,7 @@ yy.Select.prototype.compileSelectGroup2 = function (query) {
|
|
|
9754
9947
|
self.columns.forEach(function (col) {
|
|
9755
9948
|
|
|
9756
9949
|
if (query.ingroup.indexOf(col.nick) > -1) {
|
|
9757
|
-
s += "r['" + (col.as
|
|
9950
|
+
s += "r['" + (col.as ? escapeq(col.as) : col.nick) + "']=g['" + col.nick + "'];";
|
|
9758
9951
|
}
|
|
9759
9952
|
});
|
|
9760
9953
|
|
|
@@ -9764,7 +9957,7 @@ yy.Select.prototype.compileSelectGroup2 = function (query) {
|
|
|
9764
9957
|
var key = '$$$' + idx;
|
|
9765
9958
|
|
|
9766
9959
|
if (v instanceof yy.Column && query.groupColumns[v.columnid]) {
|
|
9767
|
-
s += "r['" + key + "']=r['" + v.columnid + "'];";
|
|
9960
|
+
s += "r['" + key + "']=r['" + escapeq(v.columnid) + "'];";
|
|
9768
9961
|
} else {
|
|
9769
9962
|
s += "r['" + key + "']=" + v.toJS('g', '') + ';';
|
|
9770
9963
|
}
|
|
@@ -10833,7 +11026,7 @@ yy.Op.prototype.toJS = function (context, tableid, defcols) {
|
|
|
10833
11026
|
var ljs = '(' + leftJS() + '||{})';
|
|
10834
11027
|
|
|
10835
11028
|
if (typeof this.right === 'string') {
|
|
10836
|
-
s = ljs + '["' + this.right + '"]';
|
|
11029
|
+
s = ljs + '["' + escapeq(this.right) + '"]';
|
|
10837
11030
|
} else if (typeof this.right === 'number') {
|
|
10838
11031
|
s = ljs + '[' + this.right + ']';
|
|
10839
11032
|
} else if (this.right instanceof yy.FuncValue) {
|
|
@@ -10849,7 +11042,7 @@ yy.Op.prototype.toJS = function (context, tableid, defcols) {
|
|
|
10849
11042
|
|
|
10850
11043
|
if (this.op === '!') {
|
|
10851
11044
|
if (typeof this.right === 'string') {
|
|
10852
|
-
s = '' + 'alasql.databases[alasql.useid].objects[' + leftJS() + ']["' + this.right + '"]';
|
|
11045
|
+
s = '' + 'alasql.databases[alasql.useid].objects[' + leftJS() + ']["' + escapeq(this.right) + '"]';
|
|
10853
11046
|
}
|
|
10854
11047
|
// TODO - add other cases
|
|
10855
11048
|
}
|
|
@@ -11175,7 +11368,7 @@ yy.ParamValue.prototype.toString = function () {
|
|
|
11175
11368
|
};
|
|
11176
11369
|
yy.ParamValue.prototype.toJS = function () {
|
|
11177
11370
|
if (typeof this.param === 'string') {
|
|
11178
|
-
return "params['" + this.param + "']";
|
|
11371
|
+
return "params['" + escapeq(this.param) + "']";
|
|
11179
11372
|
}
|
|
11180
11373
|
|
|
11181
11374
|
return 'params[' + this.param + ']';
|
|
@@ -12233,9 +12426,23 @@ var JSONtoString = (alasql.utils.JSONtoString = function (obj) {
|
|
|
12233
12426
|
return s;
|
|
12234
12427
|
});
|
|
12235
12428
|
|
|
12429
|
+
// A string value or key of a JSON value goes between double quotes in the generated code. A
|
|
12430
|
+
// backslash pair keeps its meaning; a lone backslash at the end, a double quote and a line break
|
|
12431
|
+
// are escaped, so the string cannot end early.
|
|
12432
|
+
function escapeJSONString(s) {
|
|
12433
|
+
return s.replace(/\\[\s\S]|\\$|"|\n|\r|\u2028|\u2029/g, function (c) {
|
|
12434
|
+
if (c.length === 2) return c;
|
|
12435
|
+
if (c === '\\') return '\\\\';
|
|
12436
|
+
if (c === '"') return '\\"';
|
|
12437
|
+
if (c === '\n') return '\\n';
|
|
12438
|
+
if (c === '\r') return '\\r';
|
|
12439
|
+
return c === '\u2028' ? '\\u2028' : '\\u2029';
|
|
12440
|
+
});
|
|
12441
|
+
}
|
|
12442
|
+
|
|
12236
12443
|
function JSONtoJS(obj, context, tableid, defcols) {
|
|
12237
12444
|
var s = '';
|
|
12238
|
-
if (typeof obj == 'string') s = '"' + obj + '"';
|
|
12445
|
+
if (typeof obj == 'string') s = '"' + escapeJSONString(obj) + '"';
|
|
12239
12446
|
else if (typeof obj == 'number') s = '(' + obj + ')';
|
|
12240
12447
|
else if (typeof obj == 'boolean') s = obj;
|
|
12241
12448
|
else if (typeof obj == 'object') {
|
|
@@ -12254,7 +12461,7 @@ function JSONtoJS(obj, context, tableid, defcols) {
|
|
|
12254
12461
|
var ss = [];
|
|
12255
12462
|
for (var k in obj) {
|
|
12256
12463
|
var s1 = '';
|
|
12257
|
-
if (typeof k == 'string') s1 += '"' + k + '"';
|
|
12464
|
+
if (typeof k == 'string') s1 += '"' + escapeJSONString(k) + '"';
|
|
12258
12465
|
else if (typeof k == 'number') s1 += k;
|
|
12259
12466
|
else if (typeof k == 'boolean') s1 += k;
|
|
12260
12467
|
else {
|
|
@@ -15632,19 +15839,19 @@ yy.SetVariable.prototype.execute = function (databaseid, params, cb) {
|
|
|
15632
15839
|
}
|
|
15633
15840
|
if (this.props && this.props.length > 0) {
|
|
15634
15841
|
if (this.method == '@') {
|
|
15635
|
-
var fs = "alasql.vars['"
|
|
15842
|
+
var fs = "alasql.vars[k('"+this.variable+"')]";
|
|
15636
15843
|
} else {
|
|
15637
|
-
var fs = "params['"
|
|
15844
|
+
var fs = "params[k('"+this.variable+"')]";
|
|
15638
15845
|
}
|
|
15639
15846
|
fs += this.props
|
|
15640
15847
|
.map(function (prop) {
|
|
15641
15848
|
if (typeof prop == 'string') {
|
|
15642
|
-
return "['"
|
|
15849
|
+
return "[k('"+prop+"')]";
|
|
15643
15850
|
} else if (typeof prop == 'number') {
|
|
15644
15851
|
return '[' + prop + ']';
|
|
15645
15852
|
} else {
|
|
15646
15853
|
|
|
15647
|
-
return
|
|
15854
|
+
return "[k("+prop.toJS()+")]";
|
|
15648
15855
|
// } else {
|
|
15649
15856
|
|
|
15650
15857
|
// throw new Error('Wrong SET property');
|
|
@@ -15652,7 +15859,7 @@ yy.SetVariable.prototype.execute = function (databaseid, params, cb) {
|
|
|
15652
15859
|
})
|
|
15653
15860
|
.join();
|
|
15654
15861
|
|
|
15655
|
-
new Function('value,params,alasql', 'var y;
|
|
15862
|
+
new Function('value,params,alasql', 'var y;var k=function(x){if(x==="__proto__"||x==="constructor"||x==="prototype")throw new Error(x+" is not allowed");return x};'+fs+'=value')(res, params, alasql);
|
|
15656
15863
|
} else {
|
|
15657
15864
|
if (this.method == '@') {
|
|
15658
15865
|
alasql.vars[this.variable] = res;
|