Compare commits

...

9 Commits

Author SHA1 Message Date
Faisal Salman
97f3368ef0 Bump version 0.7.31 2021-10-27 14:00:19 +07:00
Faisal Salman
b86860e850 Merge pull request #546 from hansott/master
 Use AST to verify whether regexes are safe
2021-10-27 06:27:06 +07:00
Faisal Salman
157af1e2f2 Merge pull request #547 from sunny-mwx/patch-1
Fix enumerize loop to only check its own properties
2021-10-26 17:51:31 +07:00
Faisal Salman
b4cfe1b624 Merge pull request #535 from shimar/fix/534-oppo-reno5-a
Enable to detect OPPO Reno5 A correctly.
2021-10-26 17:25:47 +07:00
Faisal Salman
95fea1cb26 Merge pull request #543 from catboy1006/master
feat: require the use of `===` and `!==`
2021-10-26 17:24:11 +07:00
Hans Ott
30648cef1d Use AST to verify whether regexes are safe 2021-10-26 11:36:19 +02:00
sunny-mwx
10c978eca5 Update ua-parser.js 2021-10-26 17:35:34 +08:00
chenhui9279
fbd2c6853c feat: require the use of === and !== 2021-10-25 16:44:54 +08:00
Ryohei Shima
191fed9127 Enable to detect OPPO Reno5 A correctly. 2021-10-22 12:23:36 +09:00
8 changed files with 41 additions and 21 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "ua-parser-js",
"version": "1.0.1",
"version": "0.7.31",
"authors": [
"Faisal Salman <f@faisalman.com>"
],

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,6 @@
Package.describe({
name: 'faisalman:ua-parser-js',
version: '1.0.1',
version: '0.7.31',
summary: 'Lightweight JavaScript-based user-agent string parser',
git: 'https://github.com/faisalman/ua-parser-js.git',
documentation: 'readme.md'

View File

@@ -1,7 +1,7 @@
{
"title": "UAParser.js",
"name": "ua-parser-js",
"version": "1.0.1",
"version": "0.7.31",
"author": "Faisal Salman <f@faisalman.com> (http://faisalman.com)",
"description": "Detect Browser, Engine, OS, CPU, and Device type/model from User-Agent data. Supports browser & node.js environment",
"keywords": [
@@ -156,10 +156,12 @@
],
"regs": [
"^((?:\\$|(\\s*\\*\\s*@)|(\\s*(?:var|,)?\\s+))(?:LIBVERSION|version)[\\s\\:='\"]+)([0-9]+(?:\\.[0-9]+){2,2})",
"^(\\s?\\*.*v)([0-9]+(?:\\.[0-9]+){2,2})"
"^(\\/?\\s?\\*.*v)([0-9]+(?:\\.[0-9]+){2,2})"
]
},
"devDependencies": {
"@babel/parser": "7.15.8",
"@babel/traverse": "7.15.4",
"jshint": "~2.12.0",
"mocha": "~8.2.0",
"requirejs": "^2.3.2",

View File

@@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////////////
/* UAParser.js v0.7.28
/* UAParser.js v0.7.31
Copyright © 2012-2021 Faisal Salman <f@faisalman.com>
MIT License *//*
Detect Browser, Engine, OS, CPU, and Device type/model from User-Agent data.
@@ -17,7 +17,7 @@
/////////////
var LIBVERSION = '1.0.1',
var LIBVERSION = '0.7.31',
EMPTY = '',
UNKNOWN = '?',
FUNC_TYPE = 'function',
@@ -76,7 +76,7 @@
},
enumerize = function (arr) {
var enums = {};
for (var i in arr) {
for (var i=0; i<arr.length; i++) {
enums[arr[i].toUpperCase()] = arr[i];
}
return enums;
@@ -123,7 +123,7 @@
q = props[p];
// check if given property is actually array
if (typeof q === OBJ_TYPE && q.length > 0) {
if (q.length == 2) {
if (q.length === 2) {
if (typeof q[1] == FUNC_TYPE) {
// assign modified match
this[q[0]] = q[1].call(this, match);
@@ -131,7 +131,7 @@
// assign given value, ignore regex match
this[q[0]] = q[1];
}
} else if (q.length == 3) {
} else if (q.length === 3) {
// check whether function or regex
if (typeof q[1] === FUNC_TYPE && !(q[1].exec && q[1].test)) {
// call function (usually string mapper)
@@ -140,7 +140,7 @@
// sanitize match using given regex
this[q[0]] = match ? match.replace(q[1], q[2]) : undefined;
}
} else if (q.length == 4) {
} else if (q.length === 4) {
this[q[0]] = match ? q[3].call(this, match.replace(q[1], q[2])) : undefined;
}
} else {
@@ -404,7 +404,7 @@
// OPPO
/; (\w+) bui.+ oppo/i,
/\b(cph[12]\d{3}|p(?:af|c[al]|d\w|e[ar])[mt]\d0|x9007)\b/i
/\b(cph[12]\d{3}|p(?:af|c[al]|d\w|e[ar])[mt]\d0|x9007|a101op)\b/i
], [MODEL, [VENDOR, 'OPPO'], [TYPE, MOBILE]], [
// Vivo

View File

@@ -1242,6 +1242,15 @@
"type": "mobile"
}
},
{
"desc": "OPPO Reno5 A",
"ua": "Mozilla/5.0 (Linux; Android 11; A101OP) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Mobile Safari/537.36",
"expect": {
"vendor": "OPPO",
"model": "A101OP",
"type": "mobile"
}
},
{
"desc": "OPPO Find X",
"ua": "Mozilla/5.0 (Linux; Android 8.1; PAFM00 Build/OPM1.171019.026) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Mobile Safari/537.36",

View File

@@ -2,6 +2,8 @@ var fs = require('fs');
var safe = require('safe-regex');
var assert = require('assert');
var requirejs = require('requirejs');
var parseJS = require('@babel/parser').parse;
var traverse = require('@babel/traverse').default;
var UAParser = require('./../src/ua-parser');
var browsers = require('./browser-test.json');
var cpus = require('./cpu-test.json');
@@ -137,12 +139,19 @@ describe('Testing regexes', function () {
var regexes;
// todo: use AST-based instead of grep
before('Read main js file', function (done) {
fs.readFile('src/ua-parser.js', 'utf8', function (err, data) {
regexes = data.match(/(\/.+\/[ig]+)(?=[,\s\n])/g);
done();
before('Read main js file', function () {
var code = fs.readFileSync('src/ua-parser.js', 'utf8').toString();
var ast = parseJS(code, { sourceType: "script" });
regexes = [];
traverse(ast, {
RegExpLiteral: (path) => {
regexes.push(path.node.pattern);
}
});
if (regexes.length === 0) {
throw new Error("Regexes cannot be empty!");
}
});
describe('Begin testing', function () {
@@ -156,4 +165,4 @@ describe('Testing regexes', function () {
});
});
});
})
});