@@ -164,10 +164,17 @@ function matchStrings(a: string | string[], b: string): boolean {
164164}
165165
166166// headers can be a list: e.g. ["if-match", "a, b, c"] -> "if-match: [a, b, c]"
167- function parseHeaderArray ( input ?: string ) : undefined | string | string [ ] {
168- if ( typeof input !== "string" ) return ;
169- if ( ! input . includes ( "," ) ) return input ;
170- return input . split ( "," ) . map ( ( x ) => x . trim ( ) ) ;
167+ function parseHeaderArray ( input : string ) : string | string [ ] {
168+ // split if comma found, otherwise return input
169+ if ( ! input . includes ( "," ) ) return stripQuotes ( input ) ;
170+ return input . split ( "," ) . map ( ( x ) => stripQuotes ( x ) ) ;
171+ }
172+
173+ function stripQuotes ( input : string ) : string {
174+ input = input . trim ( ) ;
175+ if ( input [ 0 ] === '"' ) input = input . slice ( 1 ) ;
176+ if ( input [ input . length - 1 ] === '"' ) input = input . slice ( 0 , - 1 ) ;
177+ return input ;
171178}
172179
173180export function parseOnlyIf (
@@ -185,18 +192,26 @@ export function parseOnlyIf(
185192 // if string list, convert to array. e.g. 'etagMatches': 'a, b, c' -> ['a', 'b', 'c']
186193 if ( typeof onlyIf . etagMatches === "string" ) {
187194 onlyIf . etagMatches = parseHeaderArray ( onlyIf . etagMatches ) ;
195+ } else if ( Array . isArray ( onlyIf . etagMatches ) ) {
196+ // otherwise if an array, strip the quotes
197+ onlyIf . etagMatches = onlyIf . etagMatches . map ( ( x ) => stripQuotes ( x ) ) ;
188198 }
189199 // if string list, convert to array. e.g. 'etagMatches': 'a, b, c' -> ['a', 'b', 'c']
190200 if ( typeof onlyIf . etagDoesNotMatch === "string" ) {
191201 onlyIf . etagDoesNotMatch = parseHeaderArray ( onlyIf . etagDoesNotMatch ) ;
202+ } else if ( Array . isArray ( onlyIf . etagDoesNotMatch ) ) {
203+ // otherwise if an array, strip the quotes
204+ onlyIf . etagDoesNotMatch = onlyIf . etagDoesNotMatch . map ( ( x ) =>
205+ stripQuotes ( x )
206+ ) ;
192207 }
193208 // if string, convert to date
194209 if ( typeof onlyIf . uploadedBefore === "string" ) {
195- onlyIf . uploadedBefore = new Date ( onlyIf . uploadedBefore ) ;
210+ onlyIf . uploadedBefore = new Date ( stripQuotes ( onlyIf . uploadedBefore ) ) ;
196211 }
197212 // if string, convert to date
198213 if ( typeof onlyIf . uploadedAfter === "string" ) {
199- onlyIf . uploadedAfter = new Date ( onlyIf . uploadedAfter ) ;
214+ onlyIf . uploadedAfter = new Date ( stripQuotes ( onlyIf . uploadedAfter ) ) ;
200215 }
201216
202217 return onlyIf as R2Conditional ;
0 commit comments