diff --git a/src/Rainbow.Tests/Storage/SfsTreeTests.PrepareItemNameForFileSystem.cs b/src/Rainbow.Tests/Storage/SfsTreeTests.PrepareItemNameForFileSystem.cs index 17e7f60..9ffa1d5 100644 --- a/src/Rainbow.Tests/Storage/SfsTreeTests.PrepareItemNameForFileSystem.cs +++ b/src/Rainbow.Tests/Storage/SfsTreeTests.PrepareItemNameForFileSystem.cs @@ -5,16 +5,15 @@ namespace Rainbow.Tests.Storage partial class SfsTreeTests { [Theory] - [InlineData("hello.yml", "hello.yml")] - [InlineData("hello\\there.yml", "hello_there.yml")] - [InlineData("hello/there.yml", "hello_there.yml")] - [InlineData("$name", "_name")] - [InlineData("hello%d", "hello_d")] - [InlineData("hello? is it you?", "hello_ is it you_")] - [InlineData("", "_html_")] - [InlineData("hello | %", "hello _ _")] - [InlineData("woo*", "woo_")] - [InlineData("yes \"sir\"", "yes _sir_")] + [InlineData("hello", "hello")] // equal + [InlineData("hello\\there", "hello_there")] // backslash + [InlineData("hello/there", "hello_there")] // forward slash + [InlineData("hello? is it you?", "hello_ is it you_")] // question mark + [InlineData("", "_html_")] // angle brackets + [InlineData("hello | ", "hello __")] // pipes + [InlineData("woo*", "woo_")] // wildcards + [InlineData("yes \"sir\"", "yes _sir_")] // quotes + [InlineData(" leading and trailing spaces ", "leading and trailing spaces_")] // should trim leading spaces, but transform trailing to underscore (ambuiguity issue, see comment in method) public void PrepareItemNameForFileSystem_FiltersIllegalCharacters(string input, string expectedOutput) { using (var testTree = new TestSfsTree()) diff --git a/src/Rainbow/Storage/SerializationFileSystemTree.cs b/src/Rainbow/Storage/SerializationFileSystemTree.cs index b41127a..4eaa0d3 100644 --- a/src/Rainbow/Storage/SerializationFileSystemTree.cs +++ b/src/Rainbow/Storage/SerializationFileSystemTree.cs @@ -531,7 +531,7 @@ protected virtual string PrepareItemNameForFileSystem(string name) { Assert.ArgumentNotNullOrEmpty(name, "name"); - var validifiedName = Regex.Replace(name, @"[%\$\\/:\*\?<>\|""]+", "_", RegexOptions.Compiled); + var validifiedName = string.Join("_", name.TrimStart(' ').Split(Path.GetInvalidFileNameChars())); if (validifiedName.Length > MaxItemNameLengthBeforeTruncation) validifiedName = validifiedName.Substring(0, MaxItemNameLengthBeforeTruncation);