alasql 2.3.1 → 2.3.3
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 +84 -41
- package/package.json +1 -1
- package/yarn-error.log +8 -8
package/bin/alasql-cli.js
CHANGED
package/dist/alasql-worker.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//! AlaSQL v2.3.
|
|
1
|
+
//! AlaSQL v2.3.3 | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
|
|
2
2
|
/*
|
|
3
3
|
@module alasql
|
|
4
|
-
@version 2.3.
|
|
4
|
+
@version 2.3.3
|
|
5
5
|
|
|
6
6
|
AlaSQL - JavaScript SQL database
|
|
7
7
|
© 2014-2016 Andrey Gershun & Mathias Rangel Wulff
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
//! AlaSQL v2.3.
|
|
1
|
+
//! AlaSQL v2.3.3 | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
|
|
2
2
|
!function(r,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=e():r.alasql=e()}(this,function(){function i(r,e,o){"function"==typeof(e=e||[])&&(scope=o,o=e,e=[]),"object"!=typeof e&&(e=[e]);var t=i.lastid++;i.buffer[t]=o,i.webworker.postMessage({id:t,sql:r,params:e})}var a;if(i.options={},i.options.progress=function(){},isArray=function(r){return"[object Array]"===Object.prototype.toString.call(r)},i.promise=function(){throw new Error("Please include a Promise/A+ library")},"undefined"!=typeof Promise&&(a=function(r,e,n,s){return new Promise(function(o,t){i(r,e,function(r,e){e?t(e):(n&&s&&!1!==i.options.progress&&i.options.progress(n,s),o(r))})})},i.promise=function(r,e){if("undefined"==typeof Promise)throw new Error("Please include a Promise/A+ library");if("string"==typeof r)return a(r,e);if(!isArray(r)||r.length<1||void 0!==e)throw new Error("Error in .promise parameters");var o=r;if(!(o.length<1)){for(var t,n,s=[],i=0;i<o.length;i++){if("string"==typeof(n=o[i])&&(n=[n]),!isArray(n)||n.length<1||2<n.length)throw new Error("Error in .promise parameter");t=n[0],n=n[1]||void 0,s.push(a(t,n,i,o.length))}return Promise.all(s)}}),i=i||!1)return i.worker=function(){throw new Error("Can find webworker in this enviroment")},"undefined"!=typeof Worker&&(i.worker=function(r,e,o){if(void 0===(r=!0===r?void 0:r))for(var t=document.getElementsByTagName("script"),n=0;n<t.length;n++){if("alasql-worker.js"===t[n].src.substr(-16).toLowerCase()){r=t[n].src.substr(0,t[n].src.length-16)+"alasql.js";break}if("alasql-worker.min.js"===t[n].src.substr(-20).toLowerCase()){r=t[n].src.substr(0,t[n].src.length-20)+"alasql.min.js";break}if("alasql.js"===t[n].src.substr(-9).toLowerCase()){r=t[n].src;break}if("alasql.min.js"===t[n].src.substr(-13).toLowerCase()){r=t[n].src.substr(0,t[n].src.length-13)+"alasql.min.js";break}}if(void 0===r)throw new Error("Path to alasql.js is not specified");var s;!1!==r?(s=(s="importScripts('")+r+"');self.onmessage = function(event) {alasql(event.data.sql,event.data.params, function(data){postMessage({id:event.data.id, data:data});});}",s=new Blob([s],{type:"text/plain"}),i.webworker=new Worker(URL.createObjectURL(s)),i.webworker.onmessage=function(r){var e=r.data.id;i.buffer[e](r.data.data),delete i.buffer[e]},i.webworker.onerror=function(r){throw r},1<arguments.length&&i("REQUIRE "+e.map(function(r){return'"'+r+'"'}).join(","),[],o)):!1===r&&delete i.webworker}),i.lastid=0,i.buffer={},i.worker(),i;throw new Error("alasql was not found")});
|
package/dist/alasql.fs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//! AlaSQL v2.3.
|
|
1
|
+
//! AlaSQL v2.3.3 | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
|
|
2
2
|
/*
|
|
3
3
|
@module alasql
|
|
4
|
-
@version 2.3.
|
|
4
|
+
@version 2.3.3
|
|
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 = '2.3.
|
|
145
|
+
alasql.version = '2.3.3';
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
148
|
Debug flag
|
|
@@ -2495,7 +2495,7 @@ next:function () {
|
|
|
2495
2495
|
|
|
2496
2496
|
// return next match that has a token
|
|
2497
2497
|
lex:function lex () {
|
|
2498
|
-
var r = this.next();
|
|
2498
|
+
var r = this.next();if(r&&/^(N?['"]__proto__['"]|\[__proto__\]|`__proto__`|__proto__)$/i.test(this.yytext))throw new Error("__proto__ is not allowed");
|
|
2499
2499
|
if (r) {
|
|
2500
2500
|
return r;
|
|
2501
2501
|
} else {
|
|
@@ -4449,9 +4449,201 @@ alasql.parser.parseError = function (str, hash) {
|
|
|
4449
4449
|
}
|
|
4450
4450
|
*/
|
|
4451
4451
|
alasql.parse = function (sql) {
|
|
4452
|
-
|
|
4452
|
+
var ast = alasqlparser.parse(alasql.utils.uncomment(sql));
|
|
4453
|
+
checkSqlNames(ast);
|
|
4454
|
+
return ast;
|
|
4453
4455
|
};
|
|
4454
4456
|
|
|
4457
|
+
/*
|
|
4458
|
+
A name from the SQL text is pasted into generated code between single quotes, so a name that
|
|
4459
|
+
holds a quote, a backslash or a line break would end the string and make the rest code
|
|
4460
|
+
(GHSA-67vj-hh8j-j94f). Such a name is refused here, once, after parsing. A name is a table,
|
|
4461
|
+
column, database, view, index, trigger or CTE name, a variable (and the keys of its path) and a
|
|
4462
|
+
table alias. The alias of a column in the select list is not a name: it is a key of the result,
|
|
4463
|
+
and the code that writes it escapes it. Strings, numbers, parameters, JavaScript and the keys
|
|
4464
|
+
of a JSON value are data, not names.
|
|
4465
|
+
*/
|
|
4466
|
+
var checkSqlNames = (function () {
|
|
4467
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
4468
|
+
var badName = /['\\\n\r\u2028\u2029]/;
|
|
4469
|
+
var nameKeys = {
|
|
4470
|
+
as: 1,
|
|
4471
|
+
columnid: 1,
|
|
4472
|
+
tableid: 1,
|
|
4473
|
+
databaseid: 1,
|
|
4474
|
+
viewid: 1,
|
|
4475
|
+
indexid: 1,
|
|
4476
|
+
trigger: 1,
|
|
4477
|
+
variable: 1,
|
|
4478
|
+
dropcolumn: 1,
|
|
4479
|
+
renamecolumn: 1,
|
|
4480
|
+
renameto: 1,
|
|
4481
|
+
to: 1,
|
|
4482
|
+
tocolumnid: 1,
|
|
4483
|
+
forcolumnid: 1,
|
|
4484
|
+
};
|
|
4485
|
+
var nameListKeys = {columns: 1, fkcolumns: 1, props: 1};
|
|
4486
|
+
|
|
4487
|
+
function checkName(name) {
|
|
4488
|
+
if (badName.test(name)) throw new SyntaxError('Not a valid name: ' + name);
|
|
4489
|
+
}
|
|
4490
|
+
|
|
4491
|
+
// ORDER BY: a name that equals an alias of the select list is that alias and is allowed (the code
|
|
4492
|
+
// escapes it), anything else is checked. (In this version a string in ORDER BY is a constant.)
|
|
4493
|
+
function checkOrder(columns, order) {
|
|
4494
|
+
var aliases = {};
|
|
4495
|
+
(columns || []).forEach(function (col) {
|
|
4496
|
+
if (col && typeof col.as === 'string') aliases[col.as] = true;
|
|
4497
|
+
});
|
|
4498
|
+
order.forEach(function (ord) {
|
|
4499
|
+
var e = ord && ord.expression;
|
|
4500
|
+
var name;
|
|
4501
|
+
if (e instanceof alasql.yy.Column && !e.tableid) name = e.columnid;
|
|
4502
|
+
if (typeof name === 'string') {
|
|
4503
|
+
if (!hasOwn.call(aliases, name)) checkName(name);
|
|
4504
|
+
return;
|
|
4505
|
+
}
|
|
4506
|
+
checkNames(ord, false, false);
|
|
4507
|
+
});
|
|
4508
|
+
}
|
|
4509
|
+
|
|
4510
|
+
// The alias of an entry of the select list, of SEARCH RETURNS and of CREATE GRAPH is a key of
|
|
4511
|
+
// the result or a variable and is allowed. The name of an entry of WITH is a table name; in a
|
|
4512
|
+
// graph item, name is data.
|
|
4513
|
+
function entryOf(node, key) {
|
|
4514
|
+
var yy = alasql.yy;
|
|
4515
|
+
if (
|
|
4516
|
+
(node instanceof yy.Select && key === 'columns') ||
|
|
4517
|
+
(node instanceof yy.CreateGraph && key === 'graph') ||
|
|
4518
|
+
(node.srchid === 'RETURN' && key === 'args')
|
|
4519
|
+
)
|
|
4520
|
+
return 'alias';
|
|
4521
|
+
if (node instanceof yy.WithSelect && key === 'withs') return 'with';
|
|
4522
|
+
return '';
|
|
4523
|
+
}
|
|
4524
|
+
|
|
4525
|
+
// Names that never reach generated code: they are used only at run time, as the key of a
|
|
4526
|
+
// database, a table, an index, a trigger or a variable, so the walk leaves them alone and such a
|
|
4527
|
+
// name keeps working. freeKeys are names of the node itself, freeChild are children whose own
|
|
4528
|
+
// names are free (what they hold is still walked), and skipChild are children that are not
|
|
4529
|
+
// walked at all (PIVOT and UNPIVOT work on the result and build no code).
|
|
4530
|
+
var varValueFree = false;
|
|
4531
|
+
var intoVarFree = false;
|
|
4532
|
+
var freeKeys = [
|
|
4533
|
+
['CreateIndex', {indexid: 1}],
|
|
4534
|
+
['DropIndex', {indexid: 1}],
|
|
4535
|
+
['Reindex', {indexid: 1}],
|
|
4536
|
+
['CreateTrigger', {trigger: 1}],
|
|
4537
|
+
['DropTrigger', {trigger: 1}],
|
|
4538
|
+
['CreateDatabase', {databaseid: 1, as: 1}],
|
|
4539
|
+
['AttachDatabase', {databaseid: 1, as: 1}],
|
|
4540
|
+
['DetachDatabase', {databaseid: 1}],
|
|
4541
|
+
['DropDatabase', {databaseid: 1}],
|
|
4542
|
+
['ShowTables', {databaseid: 1}],
|
|
4543
|
+
['ShowColumns', {databaseid: 1}],
|
|
4544
|
+
['ShowIndex', {databaseid: 1}],
|
|
4545
|
+
['ShowCreateTable', {databaseid: 1}],
|
|
4546
|
+
['AlterTable', {renameto: 1, renamecolumn: 1, dropcolumn: 1}],
|
|
4547
|
+
];
|
|
4548
|
+
var freeChild = [
|
|
4549
|
+
['CreateTable', {table: 1}],
|
|
4550
|
+
['DropTable', {tables: 1}],
|
|
4551
|
+
['TruncateTable', {table: 1}],
|
|
4552
|
+
['AlterTable', {table: 1}],
|
|
4553
|
+
['ShowColumns', {table: 1}],
|
|
4554
|
+
['ShowIndex', {table: 1}],
|
|
4555
|
+
['ShowCreateTable', {table: 1}],
|
|
4556
|
+
['CreateIndex', {table: 1}],
|
|
4557
|
+
['CreateTrigger', {table: 1}],
|
|
4558
|
+
['Declare', {declares: 1}],
|
|
4559
|
+
];
|
|
4560
|
+
var skipChild = [['Select', {pivot: 1, unpivot: 1}]];
|
|
4561
|
+
|
|
4562
|
+
function freeOf(list, node) {
|
|
4563
|
+
var yy = alasql.yy;
|
|
4564
|
+
for (var i = 0; i < list.length; i++) {
|
|
4565
|
+
var cls = yy[list[i][0]];
|
|
4566
|
+
if (cls && node instanceof cls) return list[i][1];
|
|
4567
|
+
}
|
|
4568
|
+
return null;
|
|
4569
|
+
}
|
|
4570
|
+
|
|
4571
|
+
// An @variable: an expression pastes it escaped where varValueFree is true, FROM @x pastes it
|
|
4572
|
+
// raw, and SELECT INTO @x pastes it raw where intoVarFree is false.
|
|
4573
|
+
function freeVar(node, key, entry) {
|
|
4574
|
+
var yy = alasql.yy;
|
|
4575
|
+
if (key !== 'variable' || !(node instanceof yy.VarValue)) return false;
|
|
4576
|
+
if (entry === 'source') return false;
|
|
4577
|
+
if (entry === 'into') return intoVarFree;
|
|
4578
|
+
return varValueFree;
|
|
4579
|
+
}
|
|
4580
|
+
|
|
4581
|
+
// SET @x = value without a path is a run-time assignment; with a path the name is pasted
|
|
4582
|
+
function freeSet(node, key) {
|
|
4583
|
+
var yy = alasql.yy;
|
|
4584
|
+
return key === 'variable' && yy.SetVariable && node instanceof yy.SetVariable && !(node.props && node.props.length);
|
|
4585
|
+
}
|
|
4586
|
+
|
|
4587
|
+
// data is true inside a JSON value, where a plain object is data and only a node is looked at.
|
|
4588
|
+
// entry is what entryOf says about the node as an entry of its parent, or 'free' when its own
|
|
4589
|
+
// names never reach generated code.
|
|
4590
|
+
function checkNames(node, data, entry) {
|
|
4591
|
+
if (node === null || typeof node !== 'object') return;
|
|
4592
|
+
var i;
|
|
4593
|
+
if (Array.isArray(node)) {
|
|
4594
|
+
for (i = 0; i < node.length; i++) checkNames(node[i], data, false);
|
|
4595
|
+
return;
|
|
4596
|
+
}
|
|
4597
|
+
var isNode = Object.getPrototypeOf(node) !== Object.prototype;
|
|
4598
|
+
if (data && !isNode) {
|
|
4599
|
+
for (i in node) if (hasOwn.call(node, i)) checkNames(node[i], true, false);
|
|
4600
|
+
return;
|
|
4601
|
+
}
|
|
4602
|
+
var yy = alasql.yy;
|
|
4603
|
+
if (node instanceof yy.Json) {
|
|
4604
|
+
checkNames(node.value, true, false);
|
|
4605
|
+
return;
|
|
4606
|
+
}
|
|
4607
|
+
var fk = freeOf(freeKeys, node);
|
|
4608
|
+
var fc = freeOf(freeChild, node);
|
|
4609
|
+
var sc = freeOf(skipChild, node);
|
|
4610
|
+
for (var key in node) {
|
|
4611
|
+
if (!hasOwn.call(node, key)) continue;
|
|
4612
|
+
var value = node[key];
|
|
4613
|
+
if (sc && sc[key] === 1) continue;
|
|
4614
|
+
if (key === 'order' && node instanceof yy.Select && Array.isArray(value)) {
|
|
4615
|
+
checkOrder(node.columns, value);
|
|
4616
|
+
continue;
|
|
4617
|
+
}
|
|
4618
|
+
// the column list of a WITH entry renames the result at run time
|
|
4619
|
+
var child = (fc && fc[key] === 1) || (entry === 'with' && key === 'columns') ? 'free' : '';
|
|
4620
|
+
if (!child && node instanceof yy.Select) child = key === 'from' ? 'source' : key === 'into' ? 'into' : '';
|
|
4621
|
+
if (typeof value === 'string') {
|
|
4622
|
+
if (entry === 'free' || (fk && fk[key] === 1) || freeSet(node, key) || freeVar(node, key, entry))
|
|
4623
|
+
continue;
|
|
4624
|
+
if (key === 'name' ? entry === 'with' : nameKeys[key] === 1 && !(entry === 'alias' && key === 'as'))
|
|
4625
|
+
checkName(value);
|
|
4626
|
+
} else if (value !== null && typeof value === 'object') {
|
|
4627
|
+
if (Array.isArray(value)) {
|
|
4628
|
+
for (i = 0; i < value.length; i++) {
|
|
4629
|
+
if (typeof value[i] === 'string') {
|
|
4630
|
+
if (nameListKeys[key] === 1 && entry !== 'free' && child !== 'free') checkName(value[i]);
|
|
4631
|
+
} else {
|
|
4632
|
+
checkNames(value[i], false, child || entryOf(node, key));
|
|
4633
|
+
}
|
|
4634
|
+
}
|
|
4635
|
+
} else {
|
|
4636
|
+
checkNames(value, false, child);
|
|
4637
|
+
}
|
|
4638
|
+
}
|
|
4639
|
+
}
|
|
4640
|
+
}
|
|
4641
|
+
|
|
4642
|
+
return function (ast) {
|
|
4643
|
+
checkNames(ast, false, false);
|
|
4644
|
+
};
|
|
4645
|
+
})();
|
|
4646
|
+
|
|
4455
4647
|
/**
|
|
4456
4648
|
List of engines of external databases
|
|
4457
4649
|
@type {object}
|
|
@@ -6503,7 +6695,7 @@ function queryfn3(query) {
|
|
|
6503
6695
|
|
|
6504
6696
|
// Prepare variables
|
|
6505
6697
|
query.data = [];
|
|
6506
|
-
query.xgroups
|
|
6698
|
+
query.xgroups=Object.create(null);
|
|
6507
6699
|
query.groups = [];
|
|
6508
6700
|
|
|
6509
6701
|
// Level of Joins
|
|
@@ -7544,7 +7736,7 @@ yy.Select.prototype.compile = function (databaseid, params) {
|
|
|
7544
7736
|
// Save data into parameters array
|
|
7545
7737
|
// like alasql('SELECT * INTO ? FROM ?',[outdata,srcdata]);
|
|
7546
7738
|
//
|
|
7547
|
-
query.intofns = "params['" + this.into.param + "'].push(r)";
|
|
7739
|
+
query.intofns = "params['" + escapeq(this.into.param) + "'].push(r)";
|
|
7548
7740
|
}
|
|
7549
7741
|
|
|
7550
7742
|
if (query.intofns) {
|
|
@@ -7949,7 +8141,7 @@ yy.Select.prototype.compileFrom = function (query) {
|
|
|
7949
8141
|
return res;
|
|
7950
8142
|
};
|
|
7951
8143
|
} else if (tq instanceof yy.ParamValue) {
|
|
7952
|
-
ps = "var res = alasql.prepareFromData(params['" + tq.param + "']";
|
|
8144
|
+
ps = "var res = alasql.prepareFromData(params['" + escapeq(tq.param) + "']";
|
|
7953
8145
|
|
|
7954
8146
|
if (tq.array) ps += ',true';
|
|
7955
8147
|
ps += ');if(cb)res=cb(res,idx,query);return res';
|
|
@@ -8198,7 +8390,7 @@ yy.Select.prototype.compileJoins = function (query) {
|
|
|
8198
8390
|
// source.data = ;
|
|
8199
8391
|
var jnparam = jn.param.param;
|
|
8200
8392
|
|
|
8201
|
-
ps = "var res=alasql.prepareFromData(params['" + jnparam + "']";
|
|
8393
|
+
ps = "var res=alasql.prepareFromData(params['" + escapeq(jnparam) + "']";
|
|
8202
8394
|
if (jn.array) ps += ',true';
|
|
8203
8395
|
ps += ');if(cb)res=cb(res, idx, query);return res';
|
|
8204
8396
|
|
|
@@ -8980,9 +9172,10 @@ function compileSelectStar(query, aliases, joinstar) {
|
|
|
8980
9172
|
|
|
8981
9173
|
if (columns && columns.length > 0) {
|
|
8982
9174
|
columns.forEach(function (tcol) {
|
|
9175
|
+
var escapedColumnId = escapeq(tcol.columnid);
|
|
8983
9176
|
if (joinstar && alasql.options.joinstar == 'underscore') {
|
|
8984
9177
|
ss.push(
|
|
8985
|
-
"'" + alias + '_' +
|
|
9178
|
+
"'" + alias + '_' + escapedColumnId + "':p['" + alias + "']['" + escapedColumnId + "']"
|
|
8986
9179
|
);
|
|
8987
9180
|
} else if (joinstar && alasql.options.joinstar == 'json') {
|
|
8988
9181
|
// ss.push('\''+alias+'_'+tcol.columnid+'\':p[\''+alias+'\'][\''+tcol.columnid+'\']');
|
|
@@ -8990,16 +9183,16 @@ function compileSelectStar(query, aliases, joinstar) {
|
|
|
8990
9183
|
"r['" +
|
|
8991
9184
|
alias +
|
|
8992
9185
|
"']['" +
|
|
8993
|
-
|
|
9186
|
+
escapedColumnId +
|
|
8994
9187
|
"']=p['" +
|
|
8995
9188
|
alias +
|
|
8996
9189
|
"']['" +
|
|
8997
|
-
|
|
9190
|
+
escapedColumnId +
|
|
8998
9191
|
"'];";
|
|
8999
9192
|
} else {
|
|
9000
|
-
var value = "p['" + alias + "']['" +
|
|
9193
|
+
var value = "p['" + alias + "']['" + escapedColumnId + "']";
|
|
9001
9194
|
if (!columnIds[tcol.columnid]) {
|
|
9002
|
-
var key = "'" +
|
|
9195
|
+
var key = "'" + escapedColumnId + "':";
|
|
9003
9196
|
ss.push(key + value);
|
|
9004
9197
|
columnIds[tcol.columnid] = {
|
|
9005
9198
|
id: ss.length - 1,
|
|
@@ -9030,7 +9223,7 @@ function compileSelectStar(query, aliases, joinstar) {
|
|
|
9030
9223
|
} else {
|
|
9031
9224
|
|
|
9032
9225
|
// if column not exist, then copy all
|
|
9033
|
-
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]};';
|
|
9226
|
+
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]};';
|
|
9034
9227
|
|
|
9035
9228
|
query.dirtyColumns = true;
|
|
9036
9229
|
}
|
|
@@ -9057,7 +9250,7 @@ yy.Select.prototype.compileSelect1 = function (query, params) {
|
|
|
9057
9250
|
if (col.columnid === '*') {
|
|
9058
9251
|
if (col.func) {
|
|
9059
9252
|
sp +=
|
|
9060
|
-
"r=params['" + col.param + "'](p['" + query.sources[0].alias + "'],p,params,alasql);";
|
|
9253
|
+
"r=params['" + escapeq(col.param) + "'](p['" + query.sources[0].alias + "'],p,params,alasql);";
|
|
9061
9254
|
} else if (col.tableid) {
|
|
9062
9255
|
//Copy all
|
|
9063
9256
|
var ret = compileSelectStar(query, [col.tableid], false);
|
|
@@ -9109,7 +9302,7 @@ yy.Select.prototype.compileSelect1 = function (query, params) {
|
|
|
9109
9302
|
if (isMultisheetParam) {
|
|
9110
9303
|
sp =
|
|
9111
9304
|
'var r={};var w=p["' +
|
|
9112
|
-
tbid +
|
|
9305
|
+
escapeq(tbid) +
|
|
9113
9306
|
'"];' +
|
|
9114
9307
|
'var cols=[' +
|
|
9115
9308
|
self.columns
|
|
@@ -9120,7 +9313,7 @@ yy.Select.prototype.compileSelect1 = function (query, params) {
|
|
|
9120
9313
|
'];var colas=[' +
|
|
9121
9314
|
self.columns
|
|
9122
9315
|
.map(function (col) {
|
|
9123
|
-
return "'" + (col.as || col.columnid) + "'";
|
|
9316
|
+
return "'" + escapeq(col.as || col.columnid) + "'";
|
|
9124
9317
|
})
|
|
9125
9318
|
.join(',') +
|
|
9126
9319
|
'];' +
|
|
@@ -9283,9 +9476,9 @@ yy.Select.prototype.compileSelect2 = function (query, params) {
|
|
|
9283
9476
|
this.orderColumns.forEach(function (v, idx) {
|
|
9284
9477
|
var key = '$$$' + idx;
|
|
9285
9478
|
if (v instanceof yy.Column && query.xcolumns[v.columnid]) {
|
|
9286
|
-
s += "r['" + key + "']=r['" + v.columnid + "'];";
|
|
9479
|
+
s += "r['" + key + "']=r['" + escapeq(v.columnid) + "'];";
|
|
9287
9480
|
} else if (v instanceof yy.ParamValue && query.xcolumns[params[v.param]]) {
|
|
9288
|
-
s += "r['" + key + "']=r['" + params[v.param] + "'];";
|
|
9481
|
+
s += "r['" + key + "']=r['" + escapeq(params[v.param]) + "'];";
|
|
9289
9482
|
} else {
|
|
9290
9483
|
s += "r['" + key + "']=" + v.toJS('p', query.defaultTableid, query.defcols) + ';';
|
|
9291
9484
|
}
|
|
@@ -9378,7 +9571,7 @@ yy.Select.prototype.compileSelectGroup1 = function (query) {
|
|
|
9378
9571
|
query.groupColumns[colas] = col.nick;
|
|
9379
9572
|
|
|
9380
9573
|
// if(col.as) {
|
|
9381
|
-
s += "r['" + colas + "']=";
|
|
9574
|
+
s += "r['" + (col.as !== undefined ? escapeq(colas) : colas) + "']=";
|
|
9382
9575
|
// // } else {
|
|
9383
9576
|
// // s += 'r[\''+escapeq()+'\']=';
|
|
9384
9577
|
// // };
|
|
@@ -9405,7 +9598,7 @@ yy.Select.prototype.compileSelectGroup2 = function (query) {
|
|
|
9405
9598
|
self.columns.forEach(function (col) {
|
|
9406
9599
|
|
|
9407
9600
|
if (query.ingroup.indexOf(col.nick) > -1) {
|
|
9408
|
-
s += "r['" + (col.as
|
|
9601
|
+
s += "r['" + (col.as ? escapeq(col.as) : col.nick) + "']=g['" + col.nick + "'];";
|
|
9409
9602
|
}
|
|
9410
9603
|
});
|
|
9411
9604
|
|
|
@@ -9415,7 +9608,7 @@ yy.Select.prototype.compileSelectGroup2 = function (query) {
|
|
|
9415
9608
|
var key = '$$$' + idx;
|
|
9416
9609
|
|
|
9417
9610
|
if (v instanceof yy.Column && query.groupColumns[v.columnid]) {
|
|
9418
|
-
s += "r['" + key + "']=r['" + v.columnid + "'];";
|
|
9611
|
+
s += "r['" + key + "']=r['" + escapeq(v.columnid) + "'];";
|
|
9419
9612
|
} else {
|
|
9420
9613
|
s += "r['" + key + "']=" + v.toJS('g', '') + ';';
|
|
9421
9614
|
}
|
|
@@ -10485,7 +10678,7 @@ yy.Over.prototype.toString = function () {
|
|
|
10485
10678
|
var ljs = '(' + leftJS() + '||{})';
|
|
10486
10679
|
|
|
10487
10680
|
if (typeof this.right === 'string') {
|
|
10488
|
-
s = ljs + '["' + this.right + '"]';
|
|
10681
|
+
s = ljs + '["' + escapeq(this.right) + '"]';
|
|
10489
10682
|
} else if (typeof this.right === 'number') {
|
|
10490
10683
|
s = ljs + '[' + this.right + ']';
|
|
10491
10684
|
} else if (this.right instanceof yy.FuncValue) {
|
|
@@ -10501,7 +10694,7 @@ yy.Over.prototype.toString = function () {
|
|
|
10501
10694
|
|
|
10502
10695
|
if (this.op === '!') {
|
|
10503
10696
|
if (typeof this.right === 'string') {
|
|
10504
|
-
s = '' + 'alasql.databases[alasql.useid].objects[' + leftJS() + ']["' + this.right + '"]';
|
|
10697
|
+
s = '' + 'alasql.databases[alasql.useid].objects[' + leftJS() + ']["' + escapeq(this.right) + '"]';
|
|
10505
10698
|
}
|
|
10506
10699
|
// TODO - add other cases
|
|
10507
10700
|
}
|
|
@@ -10865,7 +11058,7 @@ yy.Over.prototype.toString = function () {
|
|
|
10865
11058
|
|
|
10866
11059
|
toJS() {
|
|
10867
11060
|
if (typeof this.param === 'string') {
|
|
10868
|
-
return "params['" + this.param + "']";
|
|
11061
|
+
return "params['" + escapeq(this.param) + "']";
|
|
10869
11062
|
}
|
|
10870
11063
|
|
|
10871
11064
|
return 'params[' + this.param + ']';
|
|
@@ -11936,9 +12129,23 @@ var JSONtoString = (alasql.utils.JSONtoString = function (obj) {
|
|
|
11936
12129
|
return s;
|
|
11937
12130
|
});
|
|
11938
12131
|
|
|
12132
|
+
// A string value or key of a JSON value goes between double quotes in the generated code. A
|
|
12133
|
+
// backslash pair keeps its meaning; a lone backslash at the end, a double quote and a line break
|
|
12134
|
+
// are escaped, so the string cannot end early.
|
|
12135
|
+
function escapeJSONString(s) {
|
|
12136
|
+
return s.replace(/\\[\s\S]|\\$|"|\n|\r|\u2028|\u2029/g, function (c) {
|
|
12137
|
+
if (c.length === 2) return c;
|
|
12138
|
+
if (c === '\\') return '\\\\';
|
|
12139
|
+
if (c === '"') return '\\"';
|
|
12140
|
+
if (c === '\n') return '\\n';
|
|
12141
|
+
if (c === '\r') return '\\r';
|
|
12142
|
+
return c === '\u2028' ? '\\u2028' : '\\u2029';
|
|
12143
|
+
});
|
|
12144
|
+
}
|
|
12145
|
+
|
|
11939
12146
|
function JSONtoJS(obj, context, tableid, defcols) {
|
|
11940
12147
|
var s = '';
|
|
11941
|
-
if (typeof obj == 'string') s = '"' + obj + '"';
|
|
12148
|
+
if (typeof obj == 'string') s = '"' + escapeJSONString(obj) + '"';
|
|
11942
12149
|
else if (typeof obj == 'number') s = '(' + obj + ')';
|
|
11943
12150
|
else if (typeof obj == 'boolean') s = obj;
|
|
11944
12151
|
else if (typeof obj == 'object') {
|
|
@@ -11957,7 +12164,7 @@ function JSONtoJS(obj, context, tableid, defcols) {
|
|
|
11957
12164
|
var ss = [];
|
|
11958
12165
|
for (var k in obj) {
|
|
11959
12166
|
var s1 = '';
|
|
11960
|
-
if (typeof k == 'string') s1 += '"' + k + '"';
|
|
12167
|
+
if (typeof k == 'string') s1 += '"' + escapeJSONString(k) + '"';
|
|
11961
12168
|
else if (typeof k == 'number') s1 += k;
|
|
11962
12169
|
else if (typeof k == 'boolean') s1 += k;
|
|
11963
12170
|
else {
|
|
@@ -15363,19 +15570,19 @@ yy.SetVariable.prototype.execute = function (databaseid, params, cb) {
|
|
|
15363
15570
|
}
|
|
15364
15571
|
if (this.props && this.props.length > 0) {
|
|
15365
15572
|
if (this.method == '@') {
|
|
15366
|
-
var fs = "alasql.vars['"
|
|
15573
|
+
var fs = "alasql.vars[k('"+this.variable+"')]";
|
|
15367
15574
|
} else {
|
|
15368
|
-
var fs = "params['"
|
|
15575
|
+
var fs = "params[k('"+this.variable+"')]";
|
|
15369
15576
|
}
|
|
15370
15577
|
fs += this.props
|
|
15371
15578
|
.map(function (prop) {
|
|
15372
15579
|
if (typeof prop == 'string') {
|
|
15373
|
-
return "['"
|
|
15580
|
+
return "[k('"+prop+"')]";
|
|
15374
15581
|
} else if (typeof prop == 'number') {
|
|
15375
15582
|
return '[' + prop + ']';
|
|
15376
15583
|
} else {
|
|
15377
15584
|
|
|
15378
|
-
return
|
|
15585
|
+
return "[k("+prop.toJS()+")]";
|
|
15379
15586
|
// } else {
|
|
15380
15587
|
|
|
15381
15588
|
// throw new Error('Wrong SET property');
|
|
@@ -15383,7 +15590,7 @@ yy.SetVariable.prototype.execute = function (databaseid, params, cb) {
|
|
|
15383
15590
|
})
|
|
15384
15591
|
.join();
|
|
15385
15592
|
|
|
15386
|
-
new Function('value,params,alasql', 'var y;
|
|
15593
|
+
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);
|
|
15387
15594
|
} else {
|
|
15388
15595
|
if (this.method == '@') {
|
|
15389
15596
|
alasql.vars[this.variable] = res;
|