mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-27 07:58:45 +03:00
Revive the extensive list of MediaPlayers regexes by @leofiore as an Extension
(Original commit reference: 3fa1fe9f704d716e8f57dea46bccc5724da7b952)
This commit is contained in:
parent
9102871dea
commit
4c77c5ef21
@ -24,16 +24,22 @@ const Apps = Object.freeze({
|
||||
const Bots = Object.freeze({
|
||||
browser : [
|
||||
// Googlebot / BingBot / MSNBot / FacebookBot
|
||||
[/((?:google|bing|msn|facebook)bot(?:\-[imagevdo]{5})?|bingpreview)\/([\w\.]+)/i], [NAME, VERSION, [TYPE, 'bot']],
|
||||
[/((?:google|bing|msn|facebook)bot(?:[\-imagevdo]{0,6})|bingpreview)\/([\w\.]+)/i], [NAME, VERSION, [TYPE, 'bot']],
|
||||
|
||||
// Slackbot - https://api.slack.com/robots
|
||||
[/(slack(?:bot)?(?:-imgproxy|-linkexpanding)?) ([\w\.]+)/i], [NAME, VERSION, [TYPE, 'bot']]
|
||||
]
|
||||
});
|
||||
|
||||
const CLIs = Object.freeze({
|
||||
browser : [
|
||||
// wget / curl / lynx
|
||||
[/(wget|curl|lynx)\/([\w\.]+)/i], [NAME, VERSION, [TYPE, 'cli']]
|
||||
]
|
||||
});
|
||||
|
||||
const ExtraDevices = Object.freeze({
|
||||
device : [
|
||||
[
|
||||
device : [[
|
||||
/(nook)[\w ]+build\/(\w+)/i, // Nook
|
||||
/(dell) (strea[kpr\d ]*[\dko])/i, // Dell Streak
|
||||
/(le[- ]+pan)[- ]+(\w{1,9}) bui/i, // Le Pan Tablets
|
||||
@ -104,8 +110,7 @@ const ExtraDevices = Object.freeze({
|
||||
], [MODEL, [VENDOR, 'MachSpeed'], [TYPE, TABLET]], [
|
||||
|
||||
/\btu_(1491) b/i // Rotor Tablets
|
||||
], [MODEL, [VENDOR, 'Rotor'], [TYPE, TABLET]
|
||||
]
|
||||
], [MODEL, [VENDOR, 'Rotor'], [TYPE, TABLET]]
|
||||
]
|
||||
});
|
||||
|
||||
@ -116,17 +121,117 @@ const Emails = Object.freeze({
|
||||
]
|
||||
});
|
||||
|
||||
const CLI = Object.freeze({
|
||||
browser : [
|
||||
// wget / curl / lynx
|
||||
[/(wget|curl|lynx)\/([\w\.]+)/i], [NAME, VERSION, [TYPE, 'cli']]
|
||||
const MediaPlayers = Object.freeze({
|
||||
browser : [[
|
||||
|
||||
/(apple(?:coremedia|))\/([\w\._]+)/i, // Generic Apple CoreMedia
|
||||
/(coremedia) v([\w\._]+)/i
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/(aqualung|lyssna|bsplayer)\/([\w\.-]+)/i // Aqualung/Lyssna/BSPlayer
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/(ares|ossproxy)\s([\w\.-]+)/i // Ares/OSSProxy
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/(audacious|audimusicstream|amarok|bass|core|dalvik|gnomemplayer|music on console|nsplayer|psp-internetradioplayer|videos)\/([\w\.-]+)/i,
|
||||
// Audacious/AudiMusicStream/Amarok/BASS/OpenCORE/Dalvik/GnomeMplayer/MoC
|
||||
// NSPlayer/PSP-InternetRadioPlayer/Videos
|
||||
/(clementine|music player daemon)\s([\w\.-]+)/i, // Clementine/MPD
|
||||
/(lg player|nexplayer)\s([\d\.]+)/i,
|
||||
/player\/(nexplayer|lg player)\s([\w\.-]+)/i // NexPlayer/LG Player
|
||||
], [NAME, VERSION], [
|
||||
/(nexplayer)\s([\w\.-]+)/i // Nexplayer
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/(flrp)\/([\w\.-]+)/i // Flip Player
|
||||
], [[NAME, 'Flip Player'], VERSION], [
|
||||
|
||||
/(fstream|nativehost|queryseekspider|ia-archiver|facebookexternalhit)/i
|
||||
// FStream/NativeHost/QuerySeekSpider/IA Archiver/facebookexternalhit
|
||||
], [NAME], [
|
||||
|
||||
/(gstreamer) souphttpsrc.+libsoup\/([\w\.-]+)/i
|
||||
// Gstreamer
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/(htc streaming player)\s[\w_]+\s\/\s([\d\.]+)/i, // HTC Streaming Player
|
||||
/(java|python-urllib|python-requests|wget|libcurl)\/([\w\.-_]+)/i,
|
||||
// Java/urllib/requests/wget/cURL
|
||||
/(lavf)([\d\.]+)/i // Lavf (FFMPEG)
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/(htc_one_s)\/([\d\.]+)/i, // HTC One S
|
||||
], [[NAME, /_/g, ' '], VERSION], [
|
||||
|
||||
/(mplayer)(?:\s|\/)(?:(?:sherpya-){0,1}svn)(?:-|\s)(r\d+(?:-\d+[\w\.-]+))/i,
|
||||
// MPlayer SVN
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/(mplayer)(?:\s|\/)([\w\.-]+)/i, // MPlayer
|
||||
/(mplayer) unknown-([\w\.\-]+)/i // MPlayer UNKNOWN
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/(mplayer)/i, // MPlayer (no other info)
|
||||
/(yourmuze)/i, // YourMuze
|
||||
/(media player classic|nero showtime)/i // Media Player Classic/Nero ShowTime
|
||||
], [NAME], [
|
||||
|
||||
/(nero (?:home|scout))\/([\w\.-]+)/i // Nero Home/Nero Scout
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/(nokia\d+)\/([\w\.-]+)/i // Nokia
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/\s(songbird)\/([\w\.-]+)/i // Songbird/Philips-Songbird
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/(winamp)3 version ([\w\.-]+)/i, // Winamp
|
||||
/(winamp)\s([\w\.-]+)/i,
|
||||
/(winamp)mpeg\/([\w\.-]+)/i
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/(ocms-bot|tapinradio|tunein radio|unknown|winamp|inlight radio)/i // OCMS-bot/tap in radio/tunein/unknown/winamp (no other info)
|
||||
// inlight radio
|
||||
], [NAME], [
|
||||
|
||||
/(quicktime|rma|radioapp|radioclientapplication|soundtap|totem|stagefright|streamium)\/([\w\.-]+)/i
|
||||
// QuickTime/RealMedia/RadioApp/RadioClientApplication/
|
||||
// SoundTap/Totem/Stagefright/Streamium
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/(smp)([\d\.]+)/i // SMP
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/(vlc) media player - version ([\w\.]+)/i, // VLC Videolan
|
||||
/(vlc)\/([\w\.-]+)/i,
|
||||
/(xbmc|gvfs|xine|xmms|irapp)\/([\w\.-]+)/i, // XBMC/gvfs/Xine/XMMS/irapp
|
||||
/(foobar2000)\/([\d\.]+)/i, // Foobar2000
|
||||
/(itunes)\/([\d\.]+)/i // iTunes
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/(wmplayer)\/([\w\.-]+)/i, // Windows Media Player
|
||||
/(windows-media-player)\/([\w\.-]+)/i
|
||||
], [[NAME, /-/g, ' '], VERSION], [
|
||||
|
||||
/windows\/([\w\.-]+) upnp\/[\d\.]+ dlnadoc\/[\d\.]+ (home media server)/i,
|
||||
// Windows Media Server
|
||||
], [VERSION, [NAME, 'Windows']], [
|
||||
|
||||
/(com\.riseupradioalarm)\/([\d\.]*)/i // RiseUP Radio Alarm
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/(rad.io)\s([\d\.]+)/i, // Rad.io
|
||||
/(radio.(?:de|at|fr))\s([\d\.]+)/i
|
||||
], [[NAME, 'rad.io'], VERSION]
|
||||
]
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
Apps,
|
||||
Bots,
|
||||
CLIs,
|
||||
ExtraDevices,
|
||||
Emails,
|
||||
CLI
|
||||
MediaPlayers
|
||||
};
|
@ -1,7 +1,10 @@
|
||||
const fs = require('fs');
|
||||
const assert = require('assert');
|
||||
const safeRegex = require('safe-regex');
|
||||
const parseJS = require('@babel/parser').parse;
|
||||
const traverse = require('@babel/traverse').default;
|
||||
const safe = require('safe-regex');
|
||||
const UAParser = require('ua-parser-js');
|
||||
const { Bots, Emails, CLI } = require('ua-parser-js/extensions');
|
||||
const Ext = require('ua-parser-js/extensions');
|
||||
|
||||
describe('Bots', () => {
|
||||
it('Can detect bots', () => {
|
||||
@ -14,23 +17,53 @@ describe('Bots', () => {
|
||||
const outlook = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; Microsoft Outlook 16.0.9126; Microsoft Outlook 16.0.9126; ms-office; MSOffice 16)';
|
||||
const thunderbird = 'Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0';
|
||||
|
||||
const botParser = new UAParser(Bots);
|
||||
const botParser = new UAParser(Ext.Bots);
|
||||
assert.deepEqual(botParser.setUA(googleBot).getBrowser(), {name: "Googlebot-Video", version: "1.0", major: "1", type: "bot"});
|
||||
assert.deepEqual(botParser.setUA(msnBot).getBrowser(), {name: "msnbot-media", version: "1.1", major: "1", type: "bot"});
|
||||
assert.deepEqual(botParser.setUA(bingPreview).getBrowser(), {name: "BingPreview", version: "1.0b", major: "1", type: "bot"});
|
||||
assert.deepEqual(botParser.setUA(opera).getBrowser(), {name: "Opera", version: "8.5", major: "8"});
|
||||
|
||||
// try merging Bots & CLIs
|
||||
const botsAndCLIs = { browser : [...Bots.browser, ...CLI.browser]};
|
||||
const botsAndCLIs = { browser : [...Ext.Bots.browser, ...Ext.CLIs.browser]};
|
||||
const botsAndCLIsParser = new UAParser(botsAndCLIs);
|
||||
assert.deepEqual(botsAndCLIsParser.setUA(wget).getBrowser(), {name: "Wget", version: "1.21.1", major: "1", type:"cli"});
|
||||
assert.deepEqual(botsAndCLIsParser.setUA(facebookBot).getBrowser(), {name: "FacebookBot", version: "1.0", major: "1", type:"bot"});
|
||||
|
||||
const emailParser = new UAParser(Emails);
|
||||
const emailParser = new UAParser(Ext.Emails);
|
||||
assert.deepEqual(emailParser.setUA(outlook).getBrowser(), {name: "Microsoft Outlook", version: "16.0.9126", major: "16", type: "email"});
|
||||
assert.deepEqual(emailParser.setUA(thunderbird).getBrowser(), {name: "Thunderbird", version: "78.13.0", major: "78", type: "email"});
|
||||
});
|
||||
});
|
||||
|
||||
// TODO : move test spec to JSON file
|
||||
// TODO : check for safe-regex
|
||||
|
||||
describe('Testing regexes', () => {
|
||||
|
||||
let regexes;
|
||||
|
||||
before('Read main js file', () => {
|
||||
let code = fs.readFileSync('src/extensions/ua-parser-extensions.js', 'utf8').toString();
|
||||
let 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', () => {
|
||||
it('all regexes in extension file', () => {
|
||||
regexes.forEach(regex => {
|
||||
describe('Test against `safe-regex` : ' + regex, () => {
|
||||
it('should be safe from potentially vulnerable regex', () => {
|
||||
assert.strictEqual(safe(regex), true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user