@@ -182,6 +182,22 @@ var removeInstanceContainer = // TODO: this has a lot of overlap with instance s
182182 } ) ) ;
183183 } ;
184184
185+ /**
186+ * Remove any empty/whitespace-only env values
187+ * @param {array } req.body.env
188+ */
189+ var instanceTransformEnvs = flow . series (
190+ mw . body ( 'env' ) . require ( )
191+ . then (
192+ mw . body ( 'env' ) . array ( ) ,
193+ mw . body ( 'env' ) . mapValues ( function ( envArr ) {
194+ return envArr . filter ( function ( val ) {
195+ return ! ( / ^ \s * $ / . test ( val ) ) ;
196+ } ) ;
197+ } )
198+ )
199+ ) ;
200+
185201/** Get's the list of instances to be displayed to the user. This should contain all of the
186202 * instances owned by the owner, as well as those owned by groups (s)he is part of
187203 * @event GET rest/instances
@@ -211,6 +227,7 @@ app.get('/instances/',
211227app . post ( '/instances/' ,
212228 mw . body ( 'build' ) . require ( ) . validate ( validations . isObjectId ) ,
213229 mw . body ( 'name' , 'owner' , 'env' , 'parent' , 'build' ) . pick ( ) ,
230+ instanceTransformEnvs ,
214231 // validate body types
215232 mw . body ( 'owner.github' ) . require ( )
216233 . then (
@@ -421,6 +438,7 @@ app.patch('/instances/:id',
421438 . then (
422439 mw . body ( ) . unset ( 'build' ) ) ,
423440 mw . body ( { or : [ 'public' , 'name' , 'build' , 'env' ] } ) . require ( ) . pick ( ) ,
441+ instanceTransformEnvs ,
424442 bodyValidations ,
425443 mw . body ( { or : [ 'build' , 'name' ] } ) . require ( )
426444 . then (
0 commit comments