Commit ff3fd0e4 authored by Melissa Draper's avatar Melissa Draper

Trim directory names before they are made (bug #813905)

There are several places in the code where we make directories
for stuff, both in the filesystem and in the artefacts table.
If they have trailing spaces, then this can mess up users html
exports etc. This patch should make exports safe for existing
folders with whitespace at the end, and prevent new folders from
from being made with the problem.

Change-Id: Ia593f7f773e5ffe91ce74e8a736074b1fe1026b2
Signed-off-by: default avatarMelissa Draper <melissa@catalyst.net.nz>
parent 95290e09
......@@ -860,7 +860,7 @@ function pieform_element_filebrowser_createfolder(Pieform $form, $element, $data
$data = (object) array(
'parent' => $parentfolder,
'owner' => null,
'title' => $data['title'],
'title' => trim($data['title']),
);
if ($parentfolder) {
......@@ -938,7 +938,7 @@ function pieform_element_filebrowser_update(Pieform $form, $element, $data) {
}
}
$artefact->set('title', $data['title']);
$artefact->set('title', trim($data['title']));
$artefact->set('description', $data['description']);
$artefact->set('allowcomments', (int) $data['allowcomments']);
......
......@@ -305,7 +305,7 @@ class PluginExportHtml extends PluginExport {
* aren't legal on most real filesystems.
*/
public static function sanitise_path($path) {
return substr(str_replace('/', '_', $path), 0, 255);
return trim(substr(str_replace('/', '_', $path), 0, 255));
}
......@@ -522,7 +522,7 @@ abstract class HtmlExportArtefactPlugin {
public function paginate($artefact) {
// Create directory for storing the artefact
$dirname = PluginExportHtml::text_to_path($artefact->get('title'));
$dirname = PluginExportHtml::text_to_path(trim($artefact->get('title')));
if (!check_dir_exists($this->fileroot . $dirname)) {
throw new SystemException("Couldn't create artefact directory {$this->fileroot}{$dirname}");
}
......
......@@ -776,6 +776,7 @@ function rmdirr($dirname)
*/
function copyr($source, $dest)
{
$dest = trim($dest);
// Check for symlinks
if (is_link($source)) {
return symlink(readlink($source), $dest);
......
......@@ -1090,6 +1090,7 @@ function is_hash($array) {
function check_dir_exists($dir, $create=true, $recursive=true) {
$status = true;
$dir = trim($dir);
if(!is_dir($dir)) {
if (!$create) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment