Skip to content

Commit

Permalink
Fix issue #70, do not allow control characters in path
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Nov 12, 2022
1 parent 82856c7 commit 13e1ee1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Zio.Tests/FileSystems/TestFileSystemBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ protected void AssertCommonRead(IFileSystem fs, bool isReadOnly = false)

Assert.Throws<ArgumentNullException>(() => fs.EnumeratePaths("/", null));
Assert.Throws<ArgumentNullException>(() => fs.ConvertPathFromInternal(null));


Assert.Throws<ArgumentException>(() => fs.FileExists("/\0A.txt"));
Assert.True(fs.FileExists("/A.txt"));
Assert.True(fs.FileExists("/b.txt"));
Assert.True(fs.FileExists("/b/b.i"));
Expand Down
12 changes: 12 additions & 0 deletions src/Zio/FileSystems/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,18 @@ protected UPath ValidatePath(UPath path, string name = "path", bool allowNull =
{
return path;
}

// Make sure that we don't have any control characters in the path.
var fullPath = path.FullName;
for (var i = 0; i < fullPath.Length; i++)
{
var c = fullPath[i];
if (char.IsControl(c))
{
throw new ArgumentException($"Invalid character found \\u{(int)c:X4} at index {i}", nameof(path));
}
}

path.AssertAbsolute(name);

return ValidatePathImpl(path, name);
Expand Down

0 comments on commit 13e1ee1

Please sign in to comment.