@@ -124,16 +124,33 @@ exports.contentDisposition = deprecate.function(contentDisposition,
124124 */
125125
126126function acceptParams ( str ) {
127- var parts = str . split ( / * ; * / ) ;
128- var ret = { value : parts [ 0 ] , quality : 1 , params : { } }
127+ var length = str . length ;
128+ var colonIndex = str . indexOf ( ';' ) ;
129+ var index = colonIndex === - 1 ? length : colonIndex ;
130+ var ret = { value : str . slice ( 0 , index ) . trim ( ) , quality : 1 , params : { } } ;
129131
130- for ( var i = 1 ; i < parts . length ; ++ i ) {
131- var pms = parts [ i ] . split ( / * = * / ) ;
132- if ( 'q' === pms [ 0 ] ) {
133- ret . quality = parseFloat ( pms [ 1 ] ) ;
132+ while ( index < length ) {
133+ var splitIndex = str . indexOf ( '=' , index ) ;
134+ if ( splitIndex === - 1 ) break ;
135+
136+ var colonIndex = str . indexOf ( ';' , index ) ;
137+ var endIndex = colonIndex === - 1 ? length : colonIndex ;
138+
139+ if ( splitIndex > endIndex ) {
140+ index = str . lastIndexOf ( ';' , splitIndex - 1 ) + 1 ;
141+ continue ;
142+ }
143+
144+ var key = str . slice ( index , splitIndex ) . trim ( ) ;
145+ var value = str . slice ( splitIndex + 1 , endIndex ) . trim ( ) ;
146+
147+ if ( key === 'q' ) {
148+ ret . quality = parseFloat ( value ) ;
134149 } else {
135- ret . params [ pms [ 0 ] ] = pms [ 1 ] ;
150+ ret . params [ key ] = value ;
136151 }
152+
153+ index = endIndex + 1 ;
137154 }
138155
139156 return ret ;
0 commit comments