@@ -37,11 +37,14 @@ export const _validator = {
37
37
&& tag . Key [ 0 ] !== undefined && tag . Value [ 0 ] !== undefined
38
38
&& typeof tag . Key [ 0 ] === 'string' && typeof tag . Value [ 0 ] === 'string' ,
39
39
40
+ // Allowed characters are letters, whitespace, and numbers, plus
41
+ // the following special characters: + - = . _ : /
42
+ // Maximum key length: 128 Unicode characters
43
+ // Maximum value length: 256 Unicode characters
40
44
validateTagObjectStructure : ( tag : BucketTag ) => tag
41
45
&& Object . keys ( tag ) . length === 2
42
- && tag . Key && tag . Value
43
- && tag . Key . length >= 1 && tag . Value . length >= 1
44
- && typeof tag . Key === 'string' && typeof tag . Value === 'string' ,
46
+ && typeof tag . Key === 'string' && typeof tag . Value === 'string'
47
+ && tag . Key . length >= 1 && tag . Value . length >= 1 ,
45
48
46
49
validateXMLStructure : ( result : any ) =>
47
50
result && Object . keys ( result ) . length === 1 &&
@@ -111,8 +114,9 @@ function _validateTags(tags: Array<{ Key: string[], Value: string[] }>) {
111
114
}
112
115
// not repeating keys
113
116
if ( tags . length > Object . keys ( tagsResult ) . length ) {
114
- return errors . InvalidTag . customizeDescription ( 'Cannot provide ' +
115
- 'multiple Tags with the same key' ) ;
117
+ return errors . InvalidTag . customizeDescription (
118
+ 'Cannot provide multiple Tags with the same key'
119
+ ) ;
116
120
}
117
121
return tagsResult ;
118
122
}
@@ -138,18 +142,8 @@ export function validateTags(tags: Array<BucketTag>) {
138
142
if ( ! _validator . validateTagObjectStructure ( tag ) ) {
139
143
throw errors . MalformedXML ;
140
144
}
141
- const key = tag . Key ;
142
- const value = tag . Value ;
143
-
144
- if ( ! key ) {
145
- throw errors . InvalidTag . customizeDescription ( 'The TagKey you ' +
146
- 'have provided is invalid' ) ;
147
- }
145
+ const { Key : key , Value : value } = tag ;
148
146
149
- // Allowed characters are letters, whitespace, and numbers, plus
150
- // the following special characters: + - = . _ : /
151
- // Maximum key length: 128 Unicode characters
152
- // Maximum value length: 256 Unicode characters
153
147
const result = _validator . validateKeyValue ( key , value ) ;
154
148
if ( result instanceof Error ) {
155
149
throw result ;
0 commit comments