@@ -356,16 +356,16 @@ Device.prototype.toJSON = function toJSON() {
356
356
} ;
357
357
358
358
/**
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 .
362
362
*
363
- * @param {Boolean } refresh Refresh the dataset from the remote
363
+ * @param {String } remote optionally specify a custom URL for regex sourcing
364
364
* @api public
365
365
*/
366
- module . exports = function updater ( ) {
366
+ module . exports = function updater ( remote ) {
367
367
try {
368
- require ( './lib/update' ) . update ( function updating ( err , results ) {
368
+ require ( './lib/update' ) . update ( remote , function updating ( err , results ) {
369
369
if ( err ) {
370
370
console . log ( '[useragent] Failed to update the parsed due to an error:' ) ;
371
371
console . log ( '[useragent] ' + ( err . message ? err . message : err ) ) ;
@@ -415,15 +415,10 @@ function isSafe(userAgent) {
415
415
var consecutive = 0
416
416
, code = 0 ;
417
417
418
- if ( userAgent . length > 1000 ) return false ;
419
-
420
418
for ( var i = 0 ; i < userAgent . length ; i ++ ) {
421
419
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 ) ) {
427
422
consecutive ++ ;
428
423
} else {
429
424
consecutive = 0 ;
@@ -448,10 +443,6 @@ function isSafe(userAgent) {
448
443
* @api public
449
444
*/
450
445
exports . parse = function parse ( userAgent , jsAgent ) {
451
- if ( userAgent && userAgent . length > 1000 ) {
452
- userAgent = userAgent . substring ( 0 , 1000 ) ;
453
- }
454
-
455
446
if ( ! userAgent || ! isSafe ( userAgent ) ) return new Agent ( ) ;
456
447
457
448
var length = agentparserslength
@@ -515,8 +506,7 @@ exports.parse = function parse(userAgent, jsAgent) {
515
506
* @param {String } jsAgent Optional UA from js to detect chrome frame
516
507
* @api public
517
508
*/
518
- var lruCache = require ( 'lru-cache' ) ;
519
- var LRU = new lruCache ( 5000 ) ;
509
+ var LRU = require ( 'lru-cache' ) ( 5000 ) ;
520
510
exports . lookup = function lookup ( userAgent , jsAgent ) {
521
511
var key = ( userAgent || '' ) + ( jsAgent || '' )
522
512
, cached = LRU . get ( key ) ;
0 commit comments