WordPress.org

Make WordPress Core

Opened 21 months ago

Closed 4 weeks ago

#36170 closed enhancement (fixed)

Small refactor in the validate_file method + unit tests

Reported by: borgesbruno Owned by: johnbillion
Milestone: 4.9 Priority: normal
Severity: normal Version:
Component: Filesystem API Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

The validate_file( $file, $allowed_files = '' ) method has as third param an array of allowed files, but the default value is a string, I created this patch using as default value an empty array instead of a empty string.

Beyond that, I wrote some unit tests for this change and to improve de code coverage.

Attachments (4)

36170.diff (1.4 KB) - added by borgesbruno 21 months ago.
Patch 36170
36170.2.diff (1.5 KB) - added by borgesbruno 21 months ago.
Using type hint and changing the provider
36170.3.diff (1.5 KB) - added by borgesbruno 21 months ago.
Removing type hint
36170.4.diff (1.0 KB) - added by borgesbruno 18 months ago.

Download all attachments as: .zip

Change History (13)

@borgesbruno
21 months ago

Patch 36170

#1 @borgesbruno
21 months ago

  • Keywords has-patch has-unit-tests added

@borgesbruno
21 months ago

Using type hint and changing the provider

@borgesbruno
21 months ago

Removing type hint

#2 @borgesbruno
21 months ago

I've removed the type hint, because is also necessary to do the refactor for
validate_file_to_edit method.

Last edited 21 months ago by borgesbruno (previous) (diff)

#3 @borgesbruno
21 months ago

  • Keywords dev-feedback added

#4 @borgesbruno
21 months ago

Please review

#5 @ocean90
18 months ago

  • Component changed from General to Filesystem API
  • Keywords needs-refresh added; dev-feedback removed

@borgesbruno Thanks for your patch and the unit tests.

Can you please adjust your patch according our coding standards?

Let's change the default value for validate_file_to_edit() too.

#6 @borgesbruno
18 months ago

  • Keywords dev-feedback added; needs-refresh removed

Tks for your feedback @ocean90, to avoid theses small errors with codings standards, now I'm using the phpcs with WordPress standard mode.
I've fixed theses errors on the last patch, please, if you can review again =)

#7 @johnbillion
4 weeks ago

In 42007:

Docs: Improve the docs for validate_file() and validate_file_to_edit().

See #42016, #36170, #41017

#8 @johnbillion
4 weeks ago

  • Keywords dev-feedback removed
  • Milestone changed from Awaiting Review to 4.9
  • Owner set to johnbillion
  • Status changed from new to reviewing

#9 @johnbillion
4 weeks ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 42011:

Filesystem API: Add more specificity to the rules for valid files in validate_file().

This now treats files containing ./ as valid, and also treats files containing a trailing ../ as valid due to widespread use of this pattern in theme and plugin zip files.

Adds tests.

Props Ipstenu, borgesbruno, DavidAnderson, philipjohn, birgire
Fixes #42016, #36170

Note: See TracTickets for help on using tickets.