Enforce types
This commit is contained in:
parent
262ef7e722
commit
6eff56e2e2
@ -19,7 +19,7 @@ tree.Filter = function Filter(key, op, val, index, filename) {
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
if (ops[this.op][1]) {
|
||||
if (ops[this.op][1] == 'numeric') {
|
||||
this.val = 1 * this.val;
|
||||
}
|
||||
|
||||
@ -29,27 +29,31 @@ tree.Filter = function Filter(key, op, val, index, filename) {
|
||||
|
||||
// xmlsafe, numeric, suffix
|
||||
var ops = {
|
||||
'<': [' < ', true],
|
||||
'>': [' > ', true],
|
||||
'=': [' = ', false],
|
||||
'!=': [' != ', false],
|
||||
'<=': [' <= ', true],
|
||||
'>=': [' >= ', true],
|
||||
'=~': ['.match(', false, ')']
|
||||
'<': [' < ', 'numeric'],
|
||||
'>': [' > ', 'numeric'],
|
||||
'=': [' = ', 'both'],
|
||||
'!=': [' != ', 'both'],
|
||||
'<=': [' <= ', 'numeric'],
|
||||
'>=': [' >= ', 'numeric'],
|
||||
'=~': ['.match(', 'string', ')']
|
||||
};
|
||||
|
||||
tree.Filter.prototype.toXML = function(env) {
|
||||
if (ops[this.op][1] && isNaN(this.val)) {
|
||||
if (this.val.eval) this._val = this.val.eval(env);
|
||||
if (this.key.eval) this._key = this.key.eval(env);
|
||||
if (this._key) var key = this._key.toString(false);
|
||||
if (this._val) var val = this._val.toString(this._val.is == 'string');
|
||||
|
||||
if (
|
||||
(ops[this.op][1] == 'numeric' && isNaN(this.val)) ||
|
||||
(ops[this.op][1] == 'string' && (val || this.val)[0] != "'")
|
||||
) {
|
||||
env.error({
|
||||
message: 'Cannot use operator "' + this.op + '" with value ' + this.val,
|
||||
index: this.index,
|
||||
filename: this.filename
|
||||
});
|
||||
}
|
||||
if (this.val.eval) this._val = this.val.eval(env);
|
||||
if (this.key.eval) this._key = this.key.eval(env);
|
||||
if (this._key) var key = this._key.toString(false);
|
||||
if (this._val) var val = this._val.toString(this._val.is == 'string');
|
||||
|
||||
return '[' + (key || this.key) + ']' + ops[this.op][0] + '' + (val || this.val) + (ops[this.op][2] || '');
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user