From ba42721ca4faf56c4a346803456b5a506cd1687c Mon Sep 17 00:00:00 2001 From: Paul Nicholls Date: Thu, 25 Oct 2012 16:13:10 +1300 Subject: [PATCH 1/2] MDL-36204: moodle1 backup converter: urldecode filenames from links If filenames are not run through urldecode(), those that contain spaces (or other url-encoded characters) will not be handled, as they can't be found in the backup file. --- backup/converter/moodle1/lib.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backup/converter/moodle1/lib.php b/backup/converter/moodle1/lib.php index 86e2026b579..02256e4bbe1 100644 --- a/backup/converter/moodle1/lib.php +++ b/backup/converter/moodle1/lib.php @@ -640,7 +640,8 @@ class moodle1_converter extends base_converter { return $files; } foreach ($matches[2] as $match) { - $files[] = str_replace(array('$@FILEPHP@$', '$@SLASH@$', '$@FORCEDOWNLOAD@$'), array('', '/', ''), $match); + $file = str_replace(array('$@FILEPHP@$', '$@SLASH@$', '$@FORCEDOWNLOAD@$'), array('', '/', ''), $match); + $files[] = urldecode($file); } return array_unique($files); From 2b046f832b6aff08f00e19d7f5a6d1b73816adbb Mon Sep 17 00:00:00 2001 From: Paul Nicholls Date: Thu, 15 Nov 2012 11:41:27 +1300 Subject: [PATCH 2/2] MDL-36204: moodle1 backup converter: add unit test to cover this issue --- backup/converter/moodle1/simpletest/testlib.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/backup/converter/moodle1/simpletest/testlib.php b/backup/converter/moodle1/simpletest/testlib.php index cd1987025bf..f61be995da6 100644 --- a/backup/converter/moodle1/simpletest/testlib.php +++ b/backup/converter/moodle1/simpletest/testlib.php @@ -435,6 +435,19 @@ as it is parsed from the backup file.

download manual
'); } + public function test_referenced_files_urlencoded() { + // This test covers MDL-36204 + $text = 'This is a text containing links to file.php +as it is parsed from the backup file.

Newsno space
+
with urlencoded spaces
'; + + $files = moodle1_converter::find_referenced_files($text); + $this->assertIsA($files, 'array'); + $this->assertEqual(2, count($files)); + $this->assertTrue(in_array('/pics/news.gif', $files)); + $this->assertTrue(in_array('/pics/news with spaces.gif', $files)); + } + public function test_question_bank_conversion() { global $CFG;