MDL-68875 privacy: Keep moodle_content_writer->get_path() the same
commitb529ffad65b79d87f14ddbc051aa2ade84feccee
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Sun, 31 May 2020 13:53:40 +0000 (31 15:53 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 2 Jun 2020 13:53:45 +0000 (2 15:53 +0200)
tree25f975594b4e46d96584bfad3dba2a8d2f9e9be6
parentb5b8b1a48617b1baba95611ce6b44571d7f7dcd7
MDL-68875 privacy: Keep moodle_content_writer->get_path() the same

In MDL-62853 a new clean_param(PARAM_PATH) was added to the
moodle_content_writer->get_path() method. And this caused some
Windows tests to start failing.

The problem is that clean_param(PARAM_PATH) does normalise directory
separators to be always forward backslashes and that's normally ok
but the get_path() method has some DIRECTORY_SEPARATOR dependent code
that stopped working under windows.

After analysing various solutions, and trying to keep the behavior
EXACTLY like it was before MDL-62853, but with the cleaning included
we have applied 2 changes:

b) Move the clean_param() to later within the array_map() function,
that way the code there, that uses DIRECTORY_SEPARATOR will continue
working the same.

b) As far as there are more DIRECTORY_SEPARATOR dependent code later
in the function, also perform a str_replace() to convert back to the
OS directory separator.

Those 2 points together (a and b) make the behavior to be 100% the
original one, with separators being kept and the paths being cleaned.

This solution corresponds 100% with the proposed fixes named 3) and
4) in the issue.

Final note... all that DIRECTORY_SEPARATOR maybe needs a review because
it really shouldn't be used unless strictly needed. But that falls out
from this issue which goal was to keep things safely working like they
were before the regression (but with the cleaning applied).
privacy/classes/local/request/moodle_content_writer.php