content-type 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HISTORY.md +5 -0
- package/index.js +25 -21
- package/package.json +1 -1
package/HISTORY.md
CHANGED
package/index.js
CHANGED
|
@@ -126,34 +126,38 @@ function parse (string) {
|
|
|
126
126
|
throw new TypeError('invalid media type')
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
var key
|
|
130
|
-
var match
|
|
131
129
|
var obj = new ContentType(type.toLowerCase())
|
|
132
|
-
var value
|
|
133
130
|
|
|
134
|
-
|
|
131
|
+
// parse parameters
|
|
132
|
+
if (index !== -1) {
|
|
133
|
+
var key
|
|
134
|
+
var match
|
|
135
|
+
var value
|
|
135
136
|
|
|
136
|
-
|
|
137
|
-
if (match.index !== index) {
|
|
138
|
-
throw new TypeError('invalid parameter format')
|
|
139
|
-
}
|
|
137
|
+
PARAM_REGEXP.lastIndex = index
|
|
140
138
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
139
|
+
while ((match = PARAM_REGEXP.exec(header))) {
|
|
140
|
+
if (match.index !== index) {
|
|
141
|
+
throw new TypeError('invalid parameter format')
|
|
142
|
+
}
|
|
144
143
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
value =
|
|
148
|
-
.substr(1, value.length - 2)
|
|
149
|
-
.replace(QESC_REGEXP, '$1')
|
|
150
|
-
}
|
|
144
|
+
index += match[0].length
|
|
145
|
+
key = match[1].toLowerCase()
|
|
146
|
+
value = match[2]
|
|
151
147
|
|
|
152
|
-
|
|
153
|
-
|
|
148
|
+
if (value[0] === '"') {
|
|
149
|
+
// remove quotes and escapes
|
|
150
|
+
value = value
|
|
151
|
+
.substr(1, value.length - 2)
|
|
152
|
+
.replace(QESC_REGEXP, '$1')
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
obj.parameters[key] = value
|
|
156
|
+
}
|
|
154
157
|
|
|
155
|
-
|
|
156
|
-
|
|
158
|
+
if (index !== header.length) {
|
|
159
|
+
throw new TypeError('invalid parameter format')
|
|
160
|
+
}
|
|
157
161
|
}
|
|
158
162
|
|
|
159
163
|
return obj
|