Make sure all properties are "undefined" for is("undefined") to be true

This commit is contained in:
Faisal Salman 2023-02-19 16:43:59 +07:00
parent 746ac28f94
commit f18516c9c8
2 changed files with 17 additions and 6 deletions

View File

@ -787,12 +787,17 @@
this.rgxIs = propIs[1]; this.rgxIs = propIs[1];
} }
UAItem.prototype.is = function (strCheck) { UAItem.prototype.is = function (strCheck) {
var is = false;
for (var i in this.propIs) { for (var i in this.propIs) {
if (sanitize(this[this.propIs[i]], this.rgxIs) == sanitize(strCheck, this.rgxIs)) { if (sanitize(this[this.propIs[i]], this.rgxIs) == sanitize(strCheck, this.rgxIs)) {
return true; is = true;
if (strCheck != UNDEF_TYPE) break;
} else if (strCheck == UNDEF_TYPE && is) {
is = !is;
break;
} }
} }
return false; return is;
}; };
UAItem.prototype.toString = function () { UAItem.prototype.toString = function () {
var str = ''; var str = '';

View File

@ -205,9 +205,6 @@ describe('is() utility method', function () {
assert.strictEqual(uap.getDevice().is("mobile"), true); assert.strictEqual(uap.getDevice().is("mobile"), true);
assert.strictEqual(uap.getResult().device.is("Nokia"), true); assert.strictEqual(uap.getResult().device.is("Nokia"), true);
uap.setUA("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15");
assert.strictEqual(uap.getDevice().is("undefined"), true);
}); });
it('Should get result after reassignment', function () { it('Should get result after reassignment', function () {
@ -225,7 +222,16 @@ describe('is() utility method', function () {
assert.strictEqual(uap.getEngine().is("Blink"), true); assert.strictEqual(uap.getEngine().is("Blink"), true);
}); });
it('Should accept arch equivalent name', function () { it('Should refrain from "undefined" until all properties are checked', function () {
assert.strictEqual(uap.getDevice().is("undefined"), false);
assert.strictEqual(uap.getDevice().is("Apple"), true);
uap.setUA("");
assert.strictEqual(uap.getDevice().is("undefined"), true);
});
//it('Should accept arch equivalent name', function () {
it('Should accept exact arch name', function () {
uap.setUA("Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:19.0) Gecko/20100101 Firefox/19.0"); uap.setUA("Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:19.0) Gecko/20100101 Firefox/19.0");
assert.strictEqual(uap.getCPU().architecture, "ia32"); assert.strictEqual(uap.getCPU().architecture, "ia32");
assert.strictEqual(uap.getCPU().is("ia32"), true); assert.strictEqual(uap.getCPU().is("ia32"), true);