From fa8651a45cfec55af974766bb334b39bce3ca6a5 Mon Sep 17 00:00:00 2001
From: Adam Williams
Date: Sat, 27 Feb 2021 14:34:12 +0000
Subject: [PATCH 1/2] Remove terrible templating library
---
Gruntfile.js | 1 -
README.md | 9 +-
examples/index.html | 1 -
package.json | 5 +-
src/.wrapper.js | 8 +-
src/main.js | 2 +-
src/template.js | 257 ++++++++++++++++++++++++++------------------
tests/index.html | 1 -
8 files changed, 163 insertions(+), 121 deletions(-)
diff --git a/Gruntfile.js b/Gruntfile.js
index a2298e83..ebfea8f9 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -28,7 +28,6 @@ module.exports = function(grunt) {
],
js_files_for_standalone: [
'node_modules/jquery-extendext/jQuery.extendext.js',
- 'node_modules/dot/doT.js',
'dist/js/query-builder.js'
]
});
diff --git a/README.md b/README.md
index 262fd046..1af3ed8d 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,9 @@
[](https://david-dm.org/mistic100/jQuery-QueryBuilder)
[](https://gitlocalize.com/repo/5259/whole_project?utm_source=badge)
-jQuery plugin offering an simple interface to create complex queries.
+jQuery plugin offering a simple interface to create complex queries.
+
+**Now with 100% less unsafe-eval nonsense!**
[](https://querybuilder.js.org)
@@ -43,19 +45,16 @@ jQuery-QueryBuilder is available on [jsDelivr](https://www.jsdelivr.com/package/
* [jQuery 3](https://jquery.com)
* [Bootstrap 3](https://getbootstrap.com/docs/3.3) (CSS only)
* [jQuery.extendext](https://github.com/mistic100/jQuery.extendext)
- * [doT.js](https://olado.github.io/doT)
* [MomentJS](https://momentjs.com) (optional, for Date/Time validation)
* [SQL Parser](https://github.com/mistic100/sql-parser) (optional, for SQL methods)
* Other Bootstrap/jQuery plugins used by plugins
-($.extendext and doT.js are directly included in the [standalone](https://github.com/mistic100/jQuery-QueryBuilder/blob/master/dist/js/query-builder.standalone.js) file)
+($.extendext is directly included in the [standalone](https://github.com/mistic100/jQuery-QueryBuilder/blob/master/dist/js/query-builder.standalone.js) file)
### Browser support
* Internet Explorer >= 9
* All other recent browsers
-
-
## Build
#### Prerequisites
diff --git a/examples/index.html b/examples/index.html
index 8fc91c18..282cffe6 100644
--- a/examples/index.html
+++ b/examples/index.html
@@ -116,7 +116,6 @@ Output
-
diff --git a/package.json b/package.json
index 14a80bfd..123db3d4 100644
--- a/package.json
+++ b/package.json
@@ -10,7 +10,6 @@
"main": "dist/js/query-builder.js",
"dependencies": {
"bootstrap": "^3.4.1",
- "dot": "^1.1.3",
"jquery": "^3.5.1",
"jquery-extendext": "^1.0.0",
"moment": "^2.29.1",
@@ -64,10 +63,10 @@
"homepage": "https://querybuilder.js.org",
"repository": {
"type": "git",
- "url": "git://github.com/mistic100/jQuery-QueryBuilder.git"
+ "url": "git://github.com/lol768/jQuery-QueryBuilder.git"
},
"bugs": {
- "url": "https://github.com/mistic100/jQuery-QueryBuilder/issues"
+ "url": "https://github.com/lol768/jQuery-QueryBuilder/issues"
},
"scripts": {
"build": "grunt",
diff --git a/src/.wrapper.js b/src/.wrapper.js
index 732ae480..2b326090 100644
--- a/src/.wrapper.js
+++ b/src/.wrapper.js
@@ -1,14 +1,14 @@
(function(root, factory) {
if (typeof define == 'function' && define.amd) {
- define(['jquery', 'dot/doT', 'jquery-extendext'], factory);
+ define(['jquery', 'jquery-extendext'], factory);
}
else if (typeof module === 'object' && module.exports) {
- module.exports = factory(require('jquery'), require('dot/doT'), require('jquery-extendext'));
+ module.exports = factory(require('jquery'), require('jquery-extendext'));
}
else {
- factory(root.jQuery, root.doT);
+ factory(root.jQuery);
}
-}(this, function($, doT) {
+}(this, function($) {
"use strict";
@@js
diff --git a/src/main.js b/src/main.js
index f799af6f..1996c440 100644
--- a/src/main.js
+++ b/src/main.js
@@ -122,7 +122,7 @@ var QueryBuilder = function($el, options) {
this.templates[tpl] = QueryBuilder.templates[tpl];
}
if (typeof this.templates[tpl] == 'string') {
- this.templates[tpl] = doT.template(this.templates[tpl]);
+ console.error('Pre-compile your templates, strings are no longer supported.');
}
}, this);
diff --git a/src/template.js b/src/template.js
index 004d4693..c3d9e22c 100644
--- a/src/template.js
+++ b/src/template.js
@@ -1,109 +1,156 @@
-QueryBuilder.templates.group = '\
-';
-
-QueryBuilder.templates.rule = '\
- \
- \
- {{? it.settings.display_errors }} \
-
\
- {{?}} \
-
\
-
\
-
\
-
';
-
-QueryBuilder.templates.filterSelect = '\
-{{ var optgroup = null; }} \
-';
-
-QueryBuilder.templates.operatorSelect = '\
-{{? it.operators.length === 1 }} \
- \
-{{= it.translate("operators", it.operators[0].type) }} \
- \
-{{?}} \
-{{ var optgroup = null; }} \
-';
+const templates = {
+ /* eslint-disable */
+ group: function anonymous(it) {
+ let out = '';
+ return out;
+ },
+ rule: function anonymous(it) {
+ let out = ' ';
+ if (it.settings.display_errors) {
+ out += '
';
+ }
+ out += '
';
+ return out;
+ },
+ filterSelect: function anonymous(it) {
+ let out = '';
+ var optgroup = null;
+ out += ' ';
+ return out;
+ },
+ operatorSelect: function anonymous(it
+ ) {
+ let out = '';
+ if (it.operators.length === 1) {
+ out += ' ' + (it.translate("operators", it.operators[0].type)) + ' ';
+ }
+ out += ' ';
+ var optgroup = null;
+ out += ' ';
+ return out;
+ },
+ ruleValueSelect: function anonymous(it) {
+ let out = '';
+ var optgroup = null;
+ out += ' ';
+ return out;
+ },
+ /* eslint-enable */
+};
-QueryBuilder.templates.ruleValueSelect = '\
-{{ var optgroup = null; }} \
-';
+QueryBuilder.templates = templates;
/**
* Returns group's HTML
diff --git a/tests/index.html b/tests/index.html
index 463bc9eb..f6bfa2fc 100644
--- a/tests/index.html
+++ b/tests/index.html
@@ -27,7 +27,6 @@
-
From 685392202b44409152dd27736bad608f9f2f7d15 Mon Sep 17 00:00:00 2001
From: Adam Williams
Date: Sat, 27 Feb 2021 16:00:35 +0000
Subject: [PATCH 2/2] Make sure it actually builds
---
README.md | 3 +-
package.json | 4 +-
src/template.js | 234 ++++++++++++++++++++++++++++++++++--------------
3 files changed, 171 insertions(+), 70 deletions(-)
diff --git a/README.md b/README.md
index 1af3ed8d..682a90dc 100644
--- a/README.md
+++ b/README.md
@@ -64,7 +64,8 @@ jQuery-QueryBuilder is available on [jsDelivr](https://www.jsdelivr.com/package/
#### Run
-Install Node dependencies `npm install` then run `grunt` in the root directory to generate production files inside `dist`.
+Install Node dependencies `
+` then run `grunt` in the root directory to generate production files inside `dist`.
#### Options
diff --git a/package.json b/package.json
index 123db3d4..634deeb6 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
- "name": "jQuery-QueryBuilder",
- "version": "2.5.0",
+ "name": "jQuery-QueryBuilder-no-eval",
+ "version": "2.6.0",
"author": {
"name": "Damien \"Mistic\" Sorel",
"email": "contact@git.strangeplanet.fr",
diff --git a/src/template.js b/src/template.js
index c3d9e22c..951f4fc0 100644
--- a/src/template.js
+++ b/src/template.js
@@ -1,153 +1,253 @@
-const templates = {
+function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
+
+function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
+
+function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
+
+var templates = {
/* eslint-disable */
group: function anonymous(it) {
- let out = '