Dolibarr / dolibarr

Dolibarr ERP CRM is a modern software package to manage your company or foundation's activity (contacts, suppliers, invoices, orders, stocks, agenda, accounting, ...). it's an open source Web application (written in PHP) designed for businesses of any sizes, foundations and freelancers.
https://www.dolibarr.org
GNU General Public License v3.0
5.23k stars 2.72k forks source link

Trailing dot on Ref, filepath and filename #28961

Open Daviid-P opened 5 months ago

Daviid-P commented 5 months ago

Bug

if you create an invoice with a ref like "My_Invoice.", in windows you'll end up with Dolibarr trying to create a folder like ./facture/My_Invoice.

This will fail, if you, like me, are developing on Windows but deploying on Linux, if you want to download all documents to your PC you'll find that, while linux allows you to create a dir like test., if you mount the parent as a network share on windows you'll get a folder name like TFNZPF~9

Personally, I've added to dol_sanitizePathName the following:

$components = explode('/', $tmp);
foreach ($components as &$component) {
    $component = rtrim($component, '.');
}
$tmp = implode('/', $components);

Then in htdocs\core\lib\functions.lib.php:

function dol_mkdir($dir, $dataroot = '', $newmask = '')
{
    global $conf;

    dol_syslog('functions.lib::dol_mkdir: dir=' . $dir, LOG_INFO);

    $dir_osencoded = dol_osencode($dir);
    $dir_osencoded = dol_sanitizePathName($dir_osencoded );
    if (@is_dir($dir_osencoded)) {
        return 0;
    }

I know this is a very niche problem, but still something worth looking into.

Related to https://github.com/Dolibarr/dolibarr/issues/28627

Dolibarr Version

No response

Environment PHP

No response

Environment Database

No response

Steps to reproduce the behavior and expected behavior

No response

Attached files

No response

JonBendtsen commented 5 months ago

You could consider submitting your patches as a pull request. Another option could be to make the sanitazation characters selectable. This could be a global variable that one could set under Home, Setup, Other Setup, or this url /admin/const.php