Make WordPress Core

Opened 9 years ago

Closed 8 years ago

#35878 closed defect (bug) (wontfix)

In `wp.media.view.Attachment.render` tested parameter is missing a default.

Reported by: georgestephanis's profile georgestephanis Owned by:
Milestone: Priority: lowest
Severity: minor Version: 4.2
Component: Media Keywords: has-patch 2nd-opinion
Focuses: javascript Cc:

Description (last modified by obenland)

I'm still familiarizing myself with Media, so please feel free to just close/wontfix if this is silly.

On line ~116 in wp-includes/js/media/views/attachment.js we're testing:

if ( options.nonces ) {

but options.nonces isn't initialized above in the options defaults.

For clarity's sake, should we initialize it to false? (also, it keeps my IDE from getting cranky about it)

Patch attached.

Also -- options.percent isn't initialized either -- but as that seems to be conditionally initialized down below (only initialized if options.uploading is truthy), I didn't muck around with it in this patch.

Attachments (1)

35878.diff (891 bytes) - added by georgestephanis 9 years ago.

Download all attachments as: .zip

Change History (11)

#1 @georgestephanis
9 years ago

  • Description modified (diff)
  • Summary changed from In `wp.media.view.Attachment.render` tested parameter is missing an initialization. to In `wp.media.view.Attachment.render` tested parameter is missing a default.

#2 @obenland
9 years ago

  • Description modified (diff)

#3 @obenland
9 years ago

  • Version changed from trunk to 4.2

#4 @adamsilverstein
9 years ago

@georgestephanis Thanks for the bug report, glad to see you tinkering in the media JS.

I'm not sure we need to define nonces here or what the default would be. nonces are passed in the options (as are many other fields missing from the defaults ), but do they really have a logical default except null or undefined?

your IDE settings may need some adjusting :) what specifically is its cranky complaint and what are you linting with?

#5 @georgestephanis
9 years ago

@adamsilverstein It's PHPStorm --

https://cldup.com/UsUchArKt7.png

I guess at the least, I'd like to see the conditional changed to something like if ( 'undefined' !== typeof options.nonces ) { to make it explicit we're testing for something that may be unset?

Maybe it's just my PHP brain throwing up danger signals about testing undefined indices.

#6 @adamsilverstein
9 years ago

Hmm, I see the same thing... I'm not sure why PHP Storm is complaining.

I don't think this is an issue in JavaScript, even if the property is undefined the conditional just returns false, we don't need an isset like PHP here. undefined works fine in conditionals :)

http://cl.ly/0x0M360M3838/35878_In_wp.media.view.Attachment.render_tested_parameter_is_missing_a_default.__WordPress_Trac_2016-03-24_23-58-53.jpg

#7 @adamsilverstein
9 years ago

@georgestephanis This SO article suggested adding a doc block, which fixed the warning for me.

http://cl.ly/1z0Y3i3Z413K/attachment.js_-_develop.svn.wordpress.org_-_develop.svn.wordpress.org_2016-03-25_00-08-05.jpg

#8 @georgestephanis
9 years ago

:+1: If that resolves it, wfm!

#9 @adamsilverstein
9 years ago

Doc blocks for the win!

#10 @wonderboymusic
8 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

eh, this is fine the way it is

Note: See TracTickets for help on using tickets.