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

fix theme file collection for duplicate names #86

Merged
merged 2 commits into from
Dec 30, 2020

Conversation

stklcode
Copy link
Contributor

Part of reported regressions in the WP support forums: https://wordpress.org/support/topic/virus-alert-since-1-4-0/

WP_Theme::get_files() returns an associative array with the relative file path as key and the absolute path as value. For child themes with files matching the parent's relative paths, these got overwritten by array_merge(). We only process the absolute path, so now we strip
the values and use numeric indices which are not squashed.

Example:

$child_files = array(
	'functions.php' => '/child/functions.php',
	'header.php'    => '/child/header.php',
);
$parent_files = array(
	'functions.php' => '/parent/functions.php',
	'footer.php'    => '/parent/header.php',
);

$all_files = array_merge( $child_files, $parent_files );
/*
 * array (size=3)
 *   'functions.php' => string '/parent/functions.php' (length=21)
 *   'header.php'    => string '/child/header.php' (length=17)
 *   'footer.php'    => string '/parent/footer.php' (length=18)
 */

$child_files  = array_values( $child_files );
$parent_files = array_values( $parent_files );
$all_files    = array_merge( $child_files, $parent_files );

/*
 * array (size=4)
 *   0 => string '/child/functions.php' (length=20)
 *   1 => string '/child/header.php' (length=17)
 *   2 => string '/parent/functions.php' (length=21)
 *   3 => string '/parent/footer.php' (length=18)
 */

I've added a unit test for the Antivirus_CheckInternals class which does not yet verify any content processing, but it covers the file collection.

@codecov-io
Copy link

codecov-io commented Dec 30, 2020

Codecov Report

Merging #86 (42cdfea) into develop (9530419) will increase coverage by 13.78%.
The diff coverage is 100.00%.

Impacted file tree graph

@@              Coverage Diff               @@
##             develop      #86       +/-   ##
==============================================
+ Coverage      26.51%   40.29%   +13.78%     
  Complexity       147      147               
==============================================
  Files              5        5               
  Lines            513      546       +33     
==============================================
+ Hits             136      220       +84     
+ Misses           377      326       -51     
Impacted Files Coverage Δ Complexity Δ
inc/class-antivirus-checkinternals.php 47.10% <100.00%> (+47.10%) 38.00 <13.00> (ø)
inc/class-antivirus.php 21.93% <100.00%> (+8.70%) 83.00 <0.00> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9530419...42cdfea. Read the comment docs.

WP_Theme::get_files() returns an associative array with the relative
file path as key and the absolute path as value. For child themes
with files matching the parent's relative paths, these got overwritten
by array_merge(). We only process the absolute path, so now we strip
the values and use numeric indices which are not squashed.
@stklcode stklcode force-pushed the fix/child-theme-files branch from 0a81717 to 42cdfea Compare December 30, 2020 09:28
@stklcode stklcode added the bug label Dec 30, 2020
@stklcode stklcode added this to the 1.4.1 milestone Dec 30, 2020
@patrickrobrecht patrickrobrecht merged commit e8f60b3 into develop Dec 30, 2020
@patrickrobrecht patrickrobrecht deleted the fix/child-theme-files branch December 30, 2020 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants