mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 09:46:54 +02:00
[ImageResizer]Sanitize target file name (#14040)
* [ImageResizer] Sanitize target file name * Add a test * Avoid not recommended file names
This commit is contained in:
@@ -486,6 +486,41 @@ namespace ImageResizer.Models
|
||||
image => Assert.IsNull(((BitmapMetadata)image.Frames[0].Metadata).GetQuerySafe("System.Photo.Orientation")));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void VerifyFileNameIsSanitized()
|
||||
{
|
||||
var operation = new ResizeOperation(
|
||||
"Test.png",
|
||||
_directory,
|
||||
Settings(
|
||||
s =>
|
||||
{
|
||||
s.FileName = @"Directory\%1:*?""<>|(%2)";
|
||||
s.SelectedSize.Name = "Test\\/";
|
||||
}));
|
||||
|
||||
operation.Execute();
|
||||
|
||||
Assert.IsTrue(File.Exists(_directory + @"\Directory\Test_______(Test__).png"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void VerifyNotRecommendedNameIsChanged()
|
||||
{
|
||||
var operation = new ResizeOperation(
|
||||
"Test.png",
|
||||
_directory,
|
||||
Settings(
|
||||
s =>
|
||||
{
|
||||
s.FileName = @"nul";
|
||||
}));
|
||||
|
||||
operation.Execute();
|
||||
|
||||
Assert.IsTrue(File.Exists(_directory + @"\nul_.png"));
|
||||
}
|
||||
|
||||
private static Settings Settings(Action<Settings> action = null)
|
||||
{
|
||||
var settings = new Settings()
|
||||
|
||||
Reference in New Issue
Block a user