summaryrefslogtreecommitdiff
path: root/src/common/SyntaxChecker.js
diff options
context:
space:
mode:
authorhackademix2018-07-01 01:01:23 +0200
committerhackademix2018-07-01 01:01:23 +0200
commiteceae7187a6f0e9510bc1165f6977256b87f490f (patch)
treed943f1ec73c09efa70954dcedb55eac82a726148 /src/common/SyntaxChecker.js
downloadnoscript-eceae7187a6f0e9510bc1165f6977256b87f490f.tar.gz
noscript-eceae7187a6f0e9510bc1165f6977256b87f490f.tar.xz
noscript-eceae7187a6f0e9510bc1165f6977256b87f490f.zip
Initial commit starting at version 10.1.8.3rc4.
Diffstat (limited to 'src/common/SyntaxChecker.js')
-rw-r--r--src/common/SyntaxChecker.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/common/SyntaxChecker.js b/src/common/SyntaxChecker.js
new file mode 100644
index 0000000..8646901
--- /dev/null
+++ b/src/common/SyntaxChecker.js
@@ -0,0 +1,29 @@
+class SyntaxChecker {
+ constructor() {
+ this.lastError = null;
+ this.lastFunction = null;
+ this.lastScript = "";
+ }
+ check(script) {
+ this.lastScript = script;
+ try {
+ return !!(this.lastFunction = new Function(script));
+ } catch(e) {
+ this.lastError = e;
+ this.lastFunction = null;
+ }
+ return false;
+ }
+ unquote(s, q) {
+ // check that this is really a double or a single quoted string...
+ if (s.length > 1 && s.startsWith(q) && s.endsWith(q) &&
+ // if nothing is left if you remove all he escapes and all the stuff between quotes
+ s.replace(/\\./g, '').replace(/^(['"])[^\n\r]*?\1/, '') === '') {
+ try {
+ return eval(s);
+ } catch (e) {
+ }
+ }
+ return null;
+ }
+}