mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-11-15 14:42:16 +03:00
[fix] setUA(): remove trailing space from user-agent string
This commit is contained in:
@@ -206,10 +206,8 @@
|
|||||||
return strip(/\\?\"/g, str);
|
return strip(/\\?\"/g, str);
|
||||||
},
|
},
|
||||||
trim = function (str, len) {
|
trim = function (str, len) {
|
||||||
if (isString(str)) {
|
str = strip(/^\s\s*/, String(str));
|
||||||
str = strip(/^\s\s*/, str);
|
return typeof len === TYPEOF.UNDEFINED ? str : str.substring(0, len);
|
||||||
return typeof len === TYPEOF.UNDEFINED ? str : str.substring(0, UA_MAX_LENGTH);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////////
|
///////////////
|
||||||
@@ -1464,8 +1462,7 @@
|
|||||||
['getResult', createItemFunc(RESULT)],
|
['getResult', createItemFunc(RESULT)],
|
||||||
['getUA', function () { return userAgent; }],
|
['getUA', function () { return userAgent; }],
|
||||||
['setUA', function (ua) {
|
['setUA', function (ua) {
|
||||||
if (isString(ua))
|
if (isString(ua)) userAgent = trim(ua, UA_MAX_LENGTH);
|
||||||
userAgent = ua.length > UA_MAX_LENGTH ? trim(ua, UA_MAX_LENGTH) : ua;
|
|
||||||
return this;
|
return this;
|
||||||
}]
|
}]
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -163,6 +163,14 @@ describe('Extending Regex', function () {
|
|||||||
assert.deepEqual(myParser3.setUA(myUA2).getDevice(), {vendor: "MyTab", model: "14 Pro Max", type: "tablet"});
|
assert.deepEqual(myParser3.setUA(myUA2).getDevice(), {vendor: "MyTab", model: "14 Pro Max", type: "tablet"});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('User-agent with trailing space', function () {
|
||||||
|
it ('trailing space will be trimmed', function () {
|
||||||
|
const uastring = ' Opera/9.21 (Windows NT 5.1; U; ru) ';
|
||||||
|
const { ua } = UAParser(uastring);
|
||||||
|
assert.equal(ua, 'Opera/9.21 (Windows NT 5.1; U; ru) ');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('User-agent length', function () {
|
describe('User-agent length', function () {
|
||||||
var UA_MAX_LENGTH = 500;
|
var UA_MAX_LENGTH = 500;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user