## General help

### Editing file in browser inserts control characters

Editing file in browser inserts control characters

I'm running Moodle 1.5.3+. My faculty members and students could potentially be running any browser on any platform. When a faculty member enters the "Files" area of their site, they browse to a particular file, and click "Edit", which opens up the in-browser editor.

They make whatever necessary changes are to be made, and then click "save changes". The result is that the changes get saved, but with ^M control characters where all of the newlines occurr.

Normally I guess this wouldn't matter, except that the files they're editing are scripts that eventually get run by an external UNIX process, and the ^M characters cause unpredictable behavior. For example, if there's a ^M at the end of the first line of a shell script (ie "#!/bin/bash^M"), UNIX sees that as an invalid interpreter for the script, and things go nowhere fast.

Is there a fix for this, such that moodle can strip these characters in some proactive manner?

thanks.

Average of ratings: -
Re: Editing file in browser inserts control characters

I've fixed this for anyone who is having this problem. Any chance something like this will make it into the core code?

All I did was put this in files/index.php, in the "edit" case. If $text is set, the$fileptr is assigned, and then I put this line directly after that:

$text = preg_replace('/\x0D/', '',$text);

\x0D is the hex value for a carriage return.

Average of ratings: -