Skip to content

Commit

Permalink
webui: handle filenames containing backslashes properly
Browse files Browse the repository at this point in the history
Fixes #971: Error building tree for filenames with backslashes
  • Loading branch information
fbergkemper committed Jul 21, 2021
1 parent 7ff1f80 commit 0df1caa
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions webui/module/Restore/src/Restore/Controller/RestoreController.php
Expand Up @@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos for the canonical source repository
* @copyright Copyright (c) 2013-2020 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @copyright Copyright (c) 2013-2021 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -541,6 +541,15 @@ private function updateBvfsCache()
}
}

private function escapeNameString($n=null)
{
$n = preg_replace('/[\x00-\x1F\x7F]/', '', $n);
$replace_pairs = array('"' => '\"', '\\' => '\\\\');
$n = strtr($n, $replace_pairs);

return $n;
}

/**
* Builds a subtree as Json for JStree
*/
Expand Down Expand Up @@ -588,7 +597,7 @@ private function buildSubtree()
--$dnum;
$items .= '{';
$items .= '"id":"-' . $dir['pathid'] . '"';
$items .= ',"text":"' . preg_replace('/[\x00-\x1F\x7F]/', '', str_replace('"', '\"', $dir["name"])) . '"';
$items .= ',"text":"' . $this->escapeNameString($dir["name"]) . '"';
$items .= ',"icon":"glyphicon glyphicon-folder-close"';
$items .= ',"state":""';
$items .= ',"data":' . \Zend\Json\Json::encode($dir, \Zend\Json\Json::TYPE_OBJECT);
Expand All @@ -608,7 +617,7 @@ private function buildSubtree()
foreach($this->files as $file) {
$items .= '{';
$items .= '"id":"' . $file["fileid"] . '"';
$items .= ',"text":"' . preg_replace('/[\x00-\x1F\x7F]/', '', str_replace('"', '\"', $file["name"])) . '"';
$items .= ',"text":"' . $this->escapeNameString($file["name"]) . '"';
$items .= ',"icon":"glyphicon glyphicon-file"';
$items .= ',"state":""';
$items .= ',"data":' . \Zend\Json\Json::encode($file, \Zend\Json\Json::TYPE_OBJECT);
Expand Down

0 comments on commit 0df1caa

Please sign in to comment.