BUG: Array to String conversion when using Requirements::combine_files with path/type arguments #2501

Closed
nikrolls opened this Issue Oct 6, 2013 · 1 comment

Comments

Projects
None yet
3 participants
@nikrolls
Contributor

nikrolls commented Oct 6, 2013

When using Requirements with files whose type needs to be specified manually (eg, their extension is not 'js' or 'css'), the combine_files duplicate check throws a notice because array_intersect casts the array values to string.

Requirements::combine_files('out.min.js', array(
    array('path' => 'themes/mytheme/js/library.js.inc', 'type' => 'js')
);

The example is arbitrary; going by the above I could just rename the file, but in my real-world case I'm dealing with scripts in other languages which are compiled on load. These scripts have suffixes which shouldn't be changed.

// Requirements_Backend::combine_files
public function combine_files($combinedFileName, $files, $media = null) {
    // duplicate check
    foreach($this->combine_files as $_combinedFileName => $_files) {
        $duplicates = array_intersect($_files, $files); // -- HERE --
        if($duplicates && $combinedFileName != $_combinedFileName) {
            user_error("Requirements_Backend::combine_files(): Already included files " . implode(',', $duplicates)
                . " in combined file '{$_combinedFileName}'", E_USER_NOTICE);
            return false;
        }
    }
    ...
}

As array_intersect casts to string, it's casting the input array (and potentially any of these arrays that wind up in combine_files in future checks), causing the warning to be thrown and the comparison fail.

@simonwelsh simonwelsh added the 3.1 label Mar 15, 2014

@simonwelsh simonwelsh self-assigned this Mar 15, 2014

@simonwelsh simonwelsh removed their assignment Jul 2, 2014

@tractorcow

This comment has been minimized.

Show comment Hide comment
@tractorcow

tractorcow May 18, 2017

Contributor

The parseCombinedFile() method addresses this issue.

Contributor

tractorcow commented May 18, 2017

The parseCombinedFile() method addresses this issue.

@tractorcow tractorcow closed this May 18, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment