@@ -124,16 +124,33 @@ exports.contentDisposition = deprecate.function(contentDisposition,
124
124
*/
125
125
126
126
function 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 : { } } ;
129
131
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 ) ;
134
149
} else {
135
- ret . params [ pms [ 0 ] ] = pms [ 1 ] ;
150
+ ret . params [ key ] = value ;
136
151
}
152
+
153
+ index = endIndex + 1 ;
137
154
}
138
155
139
156
return ret ;
0 commit comments