Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

143: Fix issue when specifying a false condition for using webp #144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

@joehoyle joehoyle Oct 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry folks I missed this.

So, if we expect args.webp == true to return false in the case of "0" being passed, then I don't see why the later checks would also be failing. Should this not be something more like args.webp == "true" || args.webp == "0".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to not break the existing workaround but also support using a real truthy value.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

just a note that the string `true` does not loosely-equal the boolean value `true`

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, my bad, this I did not expect! I assumed that if ( "true" == true ) is identical to if ( "true" ) but, apparently that isn't the case.

So, just to confirm: we're expecting args.webp === "0". Currently if ( args.webp ) // when args.webp = "0" evaluates to true, so there's effectively no way to turn off webp. if ( args.webp == true ) // when args.webp = "0" evaluates to false. I don't know if it's because it's a Friday but this is totally breaking my brain :P

}

return tachyon.s3( config, key, args, function( err, data, info ) {
Expand Down