From 6e22282259b7e6036df8cfc85be04448f6955822 Mon Sep 17 00:00:00 2001 From: Sean McCafferty Date: Tue, 3 May 2022 11:37:56 -0400 Subject: [PATCH] Fix issue when specifying a false condition for using webp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `args.webp` is a string by default, so using a conditional with a string in it will always be true unless it is an empty string. This gives a very odd results to have to use `webp=` in order to force using a jpeg. Converting the parameter to a boolean fixes potential issues where future conditionals are just using `(args.webp)` where any string > 0 characters, is equal to true. In addition a conditional which doesn’t consider the datatype allows most strings to be false and `1` to be true as defined in the docs. --- server.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server.js b/server.js index 08cb8d2..1d4be1c 100644 --- a/server.js +++ b/server.js @@ -46,6 +46,9 @@ http.createServer( function( request, response ) { const args = params.query || {}; if ( typeof args.webp === 'undefined' ) { args.webp = !!( request.headers && request.headers['accept'] && request.headers['accept'].match( 'image/webp' ) ); + } else { + // args.webp will always be a string at this point, so lets convert it to a boolean to not break future conditionals. + args.webp = (args.webp == true); } return tachyon.s3( config, key, args, function( err, data, info ) {