@@ -66,6 +66,10 @@ const regexpDECRYPT = /-|_/g;
6666const regexpENCRYPT = / \/ | \+ / g;
6767const regexpUNICODE = / \\ u ( [ \d \w ] { 4 } ) / gi;
6868const regexpTERMINAL = / [ \w \S ] + / g;
69+ const regexpY = / y / g;
70+ const regexpN = / \n / g;
71+ const regexpCHARS = / \W | _ / g;
72+ const regexpCHINA = / [ \u3400 - \u9FBF ] / ;
6973const SOUNDEX = { a : '' , e : '' , i : '' , o : '' , u : '' , b : 1 , f : 1 , p : 1 , v : 1 , c : 2 , g : 2 , j : 2 , k : 2 , q : 2 , s : 2 , x : 2 , z : 2 , d : 3 , t : 3 , l : 4 , m : 5 , n : 5 , r : 6 } ;
7074const ENCODING = 'utf8' ;
7175const NEWLINE = '\r\n' ;
@@ -353,14 +357,14 @@ exports.keywords = function(content, forSearch, alternative, max_count, max_leng
353357 for ( var i = 0 , length = content . length ; i < length ; i ++ ) {
354358 if ( ! content [ i ] )
355359 continue ;
356- var tmp = ( forSearch ? content [ i ] . removeDiacritics ( ) . toLowerCase ( ) . replace ( / y / g , 'i' ) : content [ i ] . toLowerCase ( ) ) . replace ( / \n / g , ' ' ) . split ( ' ' ) ;
360+ var tmp = ( forSearch ? content [ i ] . removeDiacritics ( ) . toLowerCase ( ) . replace ( regexpY , 'i' ) : content [ i ] . toLowerCase ( ) ) . replace ( regexpN , ' ' ) . split ( ' ' ) ;
357361 if ( ! tmp || ! tmp . length )
358362 continue ;
359363 for ( var j = 0 , jl = tmp . length ; j < jl ; j ++ )
360364 words . push ( tmp [ j ] ) ;
361365 }
362366 } else
363- words = ( forSearch ? content . removeDiacritics ( ) . toLowerCase ( ) . replace ( / y / g , 'i' ) : content . toLowerCase ( ) ) . replace ( / \n / g , ' ' ) . split ( ' ' ) ;
367+ words = ( forSearch ? content . removeDiacritics ( ) . toLowerCase ( ) . replace ( regexpY , 'i' ) : content . toLowerCase ( ) ) . replace ( regexpN , ' ' ) . split ( ' ' ) ;
364368
365369 if ( ! words )
366370 words = [ ] ;
@@ -369,17 +373,34 @@ exports.keywords = function(content, forSearch, alternative, max_count, max_leng
369373 var counter = 0 ;
370374
371375 for ( var i = 0 , length = words . length ; i < length ; i ++ ) {
372- var word = words [ i ] . trim ( ) ;
376+
377+ var word = words [ i ] . trim ( ) . replace ( regexpCHARS , keywordscleaner ) ;
378+
379+ if ( regexpCHINA . test ( word ) ) {
380+
381+ var tmpw = word . split ( '' , max_count ) ;
382+
383+ for ( var j = 0 ; j < tmpw . length ; j ++ ) {
384+ word = tmpw [ j ] ;
385+ if ( dic [ word ] )
386+ dic [ word ] ++ ;
387+ else
388+ dic [ word ] = 1 ;
389+ counter ++ ;
390+ }
391+
392+ if ( counter >= max_count )
393+ break ;
394+
395+ continue ;
396+ }
373397
374398 if ( word . length < min_length )
375399 continue ;
376400
377401 if ( counter >= max_count )
378402 break ;
379403
380- if ( forSearch )
381- word = word . replace ( / \W | _ / g, '' ) ;
382-
383404 // Gets 80% length of word
384405 if ( alternative ) {
385406 if ( isSoundex )
@@ -413,6 +434,10 @@ exports.keywords = function(content, forSearch, alternative, max_count, max_leng
413434 return keys ;
414435} ;
415436
437+ function keywordscleaner ( c ) {
438+ return c . charCodeAt ( 0 ) < 200 ? '' : c ;
439+ }
440+
416441function parseProxy ( p ) {
417442 var key = 'proxy_' + p ;
418443 if ( F . temporary . other [ key ] )
@@ -638,11 +663,11 @@ function ProxyAgent(options) {
638663}
639664
640665ProxyAgent . prototype . createConnection = function ( pending ) {
641- var self = this
666+ var self = this ;
642667 self . createSocket ( pending , function ( socket ) {
643668 pending . request . onSocket ( socket ) ;
644669 } ) ;
645- }
670+ } ;
646671
647672ProxyAgent . prototype . createSocket = function ( options , callback ) {
648673
@@ -661,16 +686,12 @@ ProxyAgent.prototype.createSocket = function(options, callback) {
661686
662687 req . setTimeout ( 3000 ) ;
663688 req . on ( 'response' , proxyagent_response ) ;
664- req . on ( 'upgrade' , function ( res , socket , head ) {
665- setImmediate ( onConnect , res , socket , head )
666- } ) ;
667-
668- req . on ( 'connect' , function ( res , socket , head ) {
689+ req . on ( 'connect' , function ( res , socket ) {
669690 if ( res . statusCode === 200 ) {
670691 callback ( socket ) ;
671692 } else {
672- var err = new Error ( 'Proxy could not be established, code: ' + res . statusCode ) ;
673- err . code = 'ECONNRESET' ;
693+ var err = new Error ( 'Proxy could not be established, code: ' + res . statusCode ) ;
694+ err . code = 'ECONNRESET' ;
674695 options . request . emit ( 'error' , err ) ;
675696 }
676697 } ) ;
@@ -680,15 +701,15 @@ ProxyAgent.prototype.createSocket = function(options, callback) {
680701 } ) ;
681702
682703 req . end ( ) ;
683- }
704+ } ;
684705
685- function proxyagent_response ( ) {
706+ function proxyagent_response ( res ) {
686707 res . upgrade = true ;
687708}
688709
689710ProxyAgent . prototype . addRequest = function ( req , options ) {
690711 this . createConnection ( { host : options . host , port : options . port , request : req } ) ;
691- }
712+ } ;
692713
693714function createSecureSocket ( options , callback ) {
694715 var self = this ;
0 commit comments