Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#35878 closed defect (bug) (wontfix)

In `` 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 7 years ago.

Download all attachments as: .zip

Change History (11)

#1 @georgestephanis
7 years ago

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

#2 @obenland
7 years ago

  • Description modified (diff)

#3 @obenland
7 years ago

  • Version changed from trunk to 4.2

#4 @adamsilverstein
7 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
7 years ago

@adamsilverstein It's PHPStorm --

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
7 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 :)

#7 @adamsilverstein
7 years ago

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

#8 @georgestephanis
7 years ago

:+1: If that resolves it, wfm!

#9 @adamsilverstein
7 years ago

Doc blocks for the win!

#10 @wonderboymusic
7 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.