From 81fdd46315994d0a07bf5d8a6e4762fe5353131f Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Thu, 7 Jan 2021 08:19:25 +0000 Subject: [PATCH] MDL-70585 course: deeper clean of path names in course export. This fixes an issue on those systems that don't fully support unicode characters within zip structures, which subsequently led to broken links when browsing downloaded course content. --- lib/classes/content/export/zipwriter.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/classes/content/export/zipwriter.php b/lib/classes/content/export/zipwriter.php index ed2e2d2a8de..f23385af7e2 100644 --- a/lib/classes/content/export/zipwriter.php +++ b/lib/classes/content/export/zipwriter.php @@ -424,11 +424,14 @@ class zipwriter { * @return string */ protected function get_context_folder_name(context $context): string { + // Replace spaces with underscores, or they will be removed completely when cleaning. + $contextname = str_replace(' ', '_', $context->get_context_name()); + + // Clean the context name of all but basic characters, as some systems don't support unicode within zip structure. $shortenedname = shorten_text( - clean_param($context->get_context_name(), PARAM_FILE), + clean_param($contextname, PARAM_SAFEDIR), self::MAX_CONTEXT_NAME_LENGTH, - true, - json_decode('"' . '\u2026' . '"') + true ); return "{$shortenedname}_.{$context->id}";