Browse Source

Another rule compiler fix.

Adam Ierymenko 8 years ago
parent
commit
3f4f7145a3
3 changed files with 8 additions and 5 deletions
  1. 2 1
      rule-compiler/cli.js
  2. 1 1
      rule-compiler/package.json
  3. 5 3
      rule-compiler/rule-compiler.js

+ 2 - 1
rule-compiler/cli.js

@@ -26,9 +26,10 @@ if (err) {
 	let tagsArray = [];
 	let tagsArray = [];
 	for(let n in tags) {
 	for(let n in tags) {
 		let t = tags[n];
 		let t = tags[n];
+		let dfl = t['default'];
 		tagsArray.push({
 		tagsArray.push({
 			'id': t.id,
 			'id': t.id,
-			'default': t['default']||null
+			'default': (((dfl)||(dfl === 0)) ? dfl : null)
 		});
 		});
 	}
 	}
 
 

+ 1 - 1
rule-compiler/package.json

@@ -1,6 +1,6 @@
 {
 {
   "name": "zerotier-rule-compiler",
   "name": "zerotier-rule-compiler",
-  "version": "1.2.2-1",
+  "version": "1.2.2-2",
   "description": "ZeroTier Rule Script Compiler",
   "description": "ZeroTier Rule Script Compiler",
   "main": "cli.js",
   "main": "cli.js",
   "scripts": {
   "scripts": {

+ 5 - 3
rule-compiler/rule-compiler.js

@@ -762,7 +762,7 @@ function compile(src,rules,caps,tags)
 							return [ tag[k][1],tag[k][2],'Duplicate tag default directive.' ];
 							return [ tag[k][1],tag[k][2],'Duplicate tag default directive.' ];
 						if ((k + 1) >= tag.length)
 						if ((k + 1) >= tag.length)
 							return [ tag[k][1],tag[k][2],'Missing value for default.' ];
 							return [ tag[k][1],tag[k][2],'Missing value for default.' ];
-						dfl = tag[++k][0]||0;
+						dfl = tag[++k][0];
 					} else if (tkeyword === 'flag') {
 					} else if (tkeyword === 'flag') {
 						if ((k + 2) >= tag.length)
 						if ((k + 2) >= tag.length)
 							return [ tag[k][1],tag[k][2],'Missing tag flag name or bit index.' ];
 							return [ tag[k][1],tag[k][2],'Missing tag flag name or bit index.' ];
@@ -806,7 +806,7 @@ function compile(src,rules,caps,tags)
 				if (id < 0)
 				if (id < 0)
 					return [ tag[0][1],tag[0][2],'Tag definition is missing a numeric ID.' ];
 					return [ tag[0][1],tag[0][2],'Tag definition is missing a numeric ID.' ];
 
 
-				if (dfl !== null) {
+				if (typeof dfl === 'string') {
 					let dfl2 = enums[dfl];
 					let dfl2 = enums[dfl];
 					if (typeof dfl2 === 'number') {
 					if (typeof dfl2 === 'number') {
 						dfl = dfl2;
 						dfl = dfl2;
@@ -815,9 +815,11 @@ function compile(src,rules,caps,tags)
 						if (typeof dfl2 === 'number') {
 						if (typeof dfl2 === 'number') {
 							dfl = dfl2;
 							dfl = dfl2;
 						} else {
 						} else {
-							dfl = Math.abs(_parseNum(dfl)||0) & 0xffffffff;
+							dfl = Math.abs(parseInt(dfl)||0) & 0xffffffff;
 						}
 						}
 					}
 					}
+				} else if (typeof dfl === 'number') {
+					dfl = Math.abs(dfl) & 0xffffffff;
 				}
 				}
 
 
 				tags[tagName] = {
 				tags[tagName] = {