diff --git a/src/ua-parser.js b/src/ua-parser.js index cb60dfc..18ac0f6 100755 --- a/src/ua-parser.js +++ b/src/ua-parser.js @@ -787,12 +787,17 @@ this.rgxIs = propIs[1]; } UAItem.prototype.is = function (strCheck) { + var is = false; for (var i in this.propIs) { 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 () { var str = ''; diff --git a/test/test.js b/test/test.js index a85e9da..622df97 100644 --- a/test/test.js +++ b/test/test.js @@ -205,9 +205,6 @@ describe('is() utility method', function () { assert.strictEqual(uap.getDevice().is("mobile"), 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 () { @@ -225,7 +222,16 @@ describe('is() utility method', function () { 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"); assert.strictEqual(uap.getCPU().architecture, "ia32"); assert.strictEqual(uap.getCPU().is("ia32"), true);