Forum


Replies: 1   Views: 144
Unify path before exploding in createdocxanddownload

Posted by andrebernemann  · 19-11-2019 - 15:31

Hi,

you have changed the function createDocxAndDownload in CreateDocx.php from:

if (isset($args[0]) && !empty($args[0])) {
        $fileName = $args[0];
        $completeName = explode("/", $args[0]);
        $fileNameDownload = array_pop($completeName);
} else {
        $fileName = 'document';
        $fileNameDownload = 'document';
}

to (in 9.0 or 9.5):

if (isset($args[0]) && !empty($args[0])) {
    $fileName = $args[0];
    $completeName = explode(DIRECTORY_SEPARATOR, $args[0]);
    $fileNameDownload = array_pop($completeName);
} else {
    $fileName = 'document';
    $fileNameDownload = 'document';
}

Although, the first version is not 100% correct ($fileName is not used in the explode() stmt) it worked in my case because i use "/" as path separator. The new code does not work for me for the same reason. In my opinion, you should not rely on the DIRECTORY_SEPARATOR because developers can pass either "/" or "\\" (at least on windows).

Like you did in TransformDoc.php maybe you should better unify the separators to DIRECTORY_SEPARATOR before exploding by it like in the following suggestion:

if (isset($args[0]) && !empty($args[0])) {
        $fileName = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $args[0]);
        $completeName = explode(DIRECTORY_SEPARATOR, $fileName);
        $fileNameDownload = array_pop($completeName);
} else {
        $fileName = 'document';
        $fileNameDownload = 'document';
}

Regards,

André Bernemann

Posted by admin  · 20-11-2019 - 07:18

Hello,

Thanks for your feedback, we move it to the dev team to be checked.

Regards.