@@ -32,8 +32,11 @@ var COMMANDS = [
3232 'chmod' , 'size'
3333] ;
3434
35+ // Regular Expressions
36+ var RE_PASV = / ( [ - \d ] + , [ - \d ] + , [ - \d ] + , [ - \d ] + ) , ( [ - \d ] + ) , ( [ - \d ] + ) / ;
37+ var FTP_NEWLINE = / \r \n | \n / ;
38+
3539function getPasvPort ( text , cb ) {
36- var RE_PASV = / ( [ - \d ] + , [ - \d ] + , [ - \d ] + , [ - \d ] + ) , ( [ - \d ] + ) , ( [ - \d ] + ) / ;
3740 var match = RE_PASV . exec ( text ) ;
3841 if ( ! match ) {
3942 return cb ( new Error ( 'Bad passive host/port combination' ) ) ;
@@ -260,10 +263,11 @@ Ftp.prototype.hasFeat = function(feature) {
260263 * @return {String[] } Array of feature names
261264 */
262265Ftp . prototype . _parseFeats = function ( features ) {
263- // Ignore header and footer
264- return features . split ( / \r \n | \n / ) . slice ( 1 , - 1 ) . map ( function ( feat ) {
265- return ( / ^ \s * ( \w * ) \s * / ) . exec ( feat ) [ 1 ] . trim ( ) . toLowerCase ( ) ;
266- } ) ;
266+ // Split and ignore header and footer
267+ var featureLines = features . split ( FTP_NEWLINE ) . slice ( 1 , - 1 ) ;
268+ return featureLines
269+ . map ( function ( feat ) { return feat . trim ( ) . toLowerCase ( ) ; } )
270+ . filter ( function ( feat ) { return ! ! feat ; } ) ;
267271} ;
268272
269273// Below this point all the methods are action helpers for FTP that compose
@@ -273,8 +277,9 @@ Ftp.prototype.getFeatures = function(callback) {
273277 this . raw . feat ( function ( err , response ) {
274278 self . features = err ? [ ] : self . _parseFeats ( response . text ) ;
275279 self . raw . syst ( function ( err , res ) {
276- if ( ! err && res . code === 215 )
280+ if ( ! err && res . code === 215 ) {
277281 self . system = res . text . toLowerCase ( ) ;
282+ }
278283
279284 callback ( null , self . features ) ;
280285 } ) ;
0 commit comments