Skip to content

Commit

Permalink
Alter name generation scheme to use authoritative invalid chars list
Browse files Browse the repository at this point in the history
  • Loading branch information
kamsar committed Sep 24, 2015
1 parent 6d0869e commit f5ed0b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>", "_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>", "_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())
Expand Down
2 changes: 1 addition & 1 deletion src/Rainbow/Storage/SerializationFileSystemTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f5ed0b6

Please sign in to comment.