Skip to content

Commit e5341b1

Browse files
committed
Configurable remote, update tests.
1 parent 4c3ee79 commit e5341b1

File tree

5 files changed

+2302
-1699
lines changed

5 files changed

+2302
-1699
lines changed

Diff for: bin/update.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* Update our definition file.
77
*/
8-
require('../lib/update').update(function updating(err, data) {
8+
require('../lib/update').update(undefined, function updating(err, data) {
99
if (err) {
1010
console.error('Update unsuccessfull due to reasons');
1111
console.log(err.message);

Diff for: index.js

+9-19
Original file line numberDiff line numberDiff line change
@@ -356,16 +356,16 @@ Device.prototype.toJSON = function toJSON() {
356356
};
357357

358358
/**
359-
* Small nifty thick that allows us to download a fresh set regexs from t3h
360-
* Int3rNetz when we want to. We will be using the compiled version by default
361-
* but users can opt-in for updates.
359+
* Small nifty thick that allows us to download a fresh set regexs from a remote
360+
* source. Package uses the compiled version by default, but allow for updating from
361+
* the default source (no args) or a custom source, via the `remote` parameter.
362362
*
363-
* @param {Boolean} refresh Refresh the dataset from the remote
363+
* @param {String} remote optionally specify a custom URL for regex sourcing
364364
* @api public
365365
*/
366-
module.exports = function updater() {
366+
module.exports = function updater(remote) {
367367
try {
368-
require('./lib/update').update(function updating(err, results) {
368+
require('./lib/update').update(remote, function updating(err, results) {
369369
if (err) {
370370
console.log('[useragent] Failed to update the parsed due to an error:');
371371
console.log('[useragent] '+ (err.message ? err.message : err));
@@ -415,15 +415,10 @@ function isSafe(userAgent) {
415415
var consecutive = 0
416416
, code = 0;
417417

418-
if (userAgent.length > 1000) return false;
419-
420418
for (var i = 0; i < userAgent.length; i++) {
421419
code = userAgent.charCodeAt(i);
422-
if ((code >= 48 && code <= 57) || // numbers
423-
(code >= 65 && code <= 90) || // letters A-Z
424-
(code >= 97 && code <= 122) || // letters a-z
425-
code <= 32 // spaces and control
426-
) {
420+
// numbers between 0 and 9, letters between a and z
421+
if ((code >= 48 && code <= 57) || (code >= 97 && code <= 122)) {
427422
consecutive++;
428423
} else {
429424
consecutive = 0;
@@ -448,10 +443,6 @@ function isSafe(userAgent) {
448443
* @api public
449444
*/
450445
exports.parse = function parse(userAgent, jsAgent) {
451-
if (userAgent && userAgent.length > 1000) {
452-
userAgent = userAgent.substring(0, 1000);
453-
}
454-
455446
if (!userAgent || !isSafe(userAgent)) return new Agent();
456447

457448
var length = agentparserslength
@@ -515,8 +506,7 @@ exports.parse = function parse(userAgent, jsAgent) {
515506
* @param {String} jsAgent Optional UA from js to detect chrome frame
516507
* @api public
517508
*/
518-
var lruCache = require('lru-cache');
519-
var LRU = new lruCache(5000);
509+
var LRU = require('lru-cache')(5000);
520510
exports.lookup = function lookup(userAgent, jsAgent) {
521511
var key = (userAgent || '')+(jsAgent || '')
522512
, cached = LRU.get(key);

0 commit comments

Comments
 (0)