mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-27 16:08:47 +03:00
Fix: accept empty string as input
This commit is contained in:
parent
feefb81cd0
commit
35c2b91534
@ -918,10 +918,10 @@
|
|||||||
// Constructor
|
// Constructor
|
||||||
////////////////
|
////////////////
|
||||||
|
|
||||||
function UACHData (uach, isHTTP_UACH) {
|
function UACHData (uach, isHttpUACH) {
|
||||||
uach = uach || {};
|
uach = uach || {};
|
||||||
setProps.call(this, CH_ALL_VALUES);
|
setProps.call(this, CH_ALL_VALUES);
|
||||||
if (isHTTP_UACH) {
|
if (isHttpUACH) {
|
||||||
setProps.call(this, [
|
setProps.call(this, [
|
||||||
[BRANDS, itemListToArray(uach[CH_HEADER])],
|
[BRANDS, itemListToArray(uach[CH_HEADER])],
|
||||||
[FULLVERLIST, itemListToArray(uach[CH_HEADER_FULL_VER_LIST])],
|
[FULLVERLIST, itemListToArray(uach[CH_HEADER_FULL_VER_LIST])],
|
||||||
@ -1106,15 +1106,12 @@
|
|||||||
return new UAParser(ua, extensions, headers).getResult();
|
return new UAParser(ua, extensions, headers).getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
var userAgent = ua ||
|
var userAgent = typeof ua === STR_TYPE ? ua : // Passed user-agent string
|
||||||
((NAVIGATOR && NAVIGATOR.userAgent) ?
|
((NAVIGATOR && NAVIGATOR.userAgent) ? NAVIGATOR.userAgent : // navigator.userAgent
|
||||||
NAVIGATOR.userAgent :
|
(headers && headers[USER_AGENT] ? headers[USER_AGENT] : // User-Agent from passed headers
|
||||||
(headers && headers[USER_AGENT] ?
|
EMPTY)), // empty string
|
||||||
headers[USER_AGENT] :
|
|
||||||
EMPTY)),
|
|
||||||
|
|
||||||
HTTP_UACH = new UACHData(headers, true),
|
|
||||||
|
|
||||||
|
httpUACH = new UACHData(headers, true),
|
||||||
regexMap = extensions ?
|
regexMap = extensions ?
|
||||||
extend(defaultRegexes, extensions) :
|
extend(defaultRegexes, extensions) :
|
||||||
defaultRegexes,
|
defaultRegexes,
|
||||||
@ -1122,7 +1119,7 @@
|
|||||||
createItemFunc = function (itemType) {
|
createItemFunc = function (itemType) {
|
||||||
if (itemType == UA_RESULT) {
|
if (itemType == UA_RESULT) {
|
||||||
return function () {
|
return function () {
|
||||||
return new UAItem(itemType, userAgent, regexMap, HTTP_UACH)
|
return new UAItem(itemType, userAgent, regexMap, httpUACH)
|
||||||
.set('ua', userAgent)
|
.set('ua', userAgent)
|
||||||
.set(UA_BROWSER, this.getBrowser())
|
.set(UA_BROWSER, this.getBrowser())
|
||||||
.set(UA_CPU, this.getCPU())
|
.set(UA_CPU, this.getCPU())
|
||||||
@ -1133,7 +1130,7 @@
|
|||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return function () {
|
return function () {
|
||||||
return new UAItem(itemType, userAgent, regexMap[itemType], HTTP_UACH)
|
return new UAItem(itemType, userAgent, regexMap[itemType], httpUACH)
|
||||||
.parseUA()
|
.parseUA()
|
||||||
.get();
|
.get();
|
||||||
};
|
};
|
||||||
|
@ -5,6 +5,18 @@ import url from 'url';
|
|||||||
|
|
||||||
const localHtml = `file://${path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), '../')}/dist/ua-parser.html`;
|
const localHtml = `file://${path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), '../')}/dist/ua-parser.html`;
|
||||||
|
|
||||||
|
test.describe('test input', () => {
|
||||||
|
test.beforeEach(async ({ page }) => {
|
||||||
|
await page.goto(localHtml);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('accept empty string', async ({ page }) => {
|
||||||
|
// @ts-ignore
|
||||||
|
const uap = await page.evaluate(async () => await UAParser(''));
|
||||||
|
expect(uap).toHaveProperty('ua', '');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('read client hints data', async ({ page }) => {
|
test('read client hints data', async ({ page }) => {
|
||||||
await page.addInitScript(() => {
|
await page.addInitScript(() => {
|
||||||
Object.defineProperty(navigator, 'userAgentData', {
|
Object.defineProperty(navigator, 'userAgentData', {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user