Illegal characters in path (FIXED - code included)

Topics: General, Installing Orchard
Aug 11, 2011 at 4:47 PM

Hi, there have been a few people posting about problems with the exception "Illegal characters in path", when reading settings.txt

The problem arises when reading Settings.txt. in ShellSettingsManager.cs

The code reads the whole file into a string, and then splits the string into "lines" using this :

var settings = text.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

If you settings file has its line ending as LF, rather than CRLF, then the code above reads the entire file into a single item (ie the array has one single entry).

Then later on in the code, it assigns the contents of the entire file to the settings.Name field.

This causes the bug in ShellContainerFactory.cs when doing this : 

var optionalShellByNameConfig = HostingEnvironment.MapPath("~/Config/Sites." + settings.Name + ".config");

Because the settings.Name has the entire contents of the file in the string - not the expected value which is, for example, "Default".

In order to avoid this, below is a fix (ShellSettingsManager.cs)

Current code (1.2.41) : 

            var settings = text.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var setting in settings) {

Fixed code :

            var reader = new StringReader(text);
            string setting;
            while ((setting = reader.ReadLine()) != null) {
                if (string.IsNullOrEmpty(setting)) continue;

This fix works, because the current code relies on the fact that the Settings.txt file has line endings of CRLF.

But the StringReader class handles either LF or CRLF.

Alternatively, make sure your line endings on Settings.txt are CRLF !

Ben

Coordinator
Aug 11, 2011 at 7:18 PM

You could create a pull request for that on 1.x. I will take it, thanks.