raffaelj / CpMultiplane

small PHP frontend for Cockpit CMS
MIT License
17 stars 3 forks source link

Prevent "C:\" expansion #30

Closed Raruto closed 3 years ago

Raruto commented 3 years ago

This pull is related to a problem while running the following command (on Windows OS):

php ./mp multiplane/load-i18n

copy

Problematic line CpMultiplane/modules/Multiplane/cli/multiplane/load-i18n.php#L166:

// CpMultiplane/modules/Multiplane/cli/multiplane/load-i18n.php#L166

$fs->copy($file->getRealPath(), "{$dest}/{$code}.js")

// BEFORE EXECUTION:
// source path:      D:\htdocs\cpmp-lib-skeleton\cpdata\storage\tmp\tinymce_languages\langs\it_IT.js
// destination path: D:/htdocs/cpmp-lib-skeleton/cpdata/storage/assets/cockpit/i18n/tinymce/it_IT.js

// AFTER EXECUTION:
// source path:      D:\htdocs\cpmp-lib-skeleton\cpdata\storage\tmp\tinymce_languages\langs\it_IT.js
// destination path: false

Source of the problematic command: cockpit/lib/LimeExtra/Helper/Filesystem.php#L161-L166

// cockpit/lib/LimeExtra/Helper/Filesystem.php#L161-L166

/**
 * @param $path
 * @param $dest
 * @param bool|true $_init
 * @return bool
 */
public function copy($path, $dest, $_init = true) {

  if ($_init) {
    if (\strpos($path, ':')) $path = $this->app->path($path); // not expanded because $path exists
    if (\strpos($dest, ':')) $dest = $this->app->path($dest); // return false, because $dest path doesn't exists yet 
  }
...

Essentially the $_init parameter allows you to specify whether D:/ is interpreted as a cockpit configuration parameter.

raffaelj commented 3 years ago

Thanks. Oh and obviously true was false, so in this case true == false ;-)