Skip to content

Commit

Permalink
more AgainstBadExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jun 14, 2024
1 parent 49d0af1 commit 0b9a55b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/Verify/FilePair.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
namespace VerifyTests;

public readonly struct FilePair(string extension, string receivedPath, string verifiedPath)
public readonly struct FilePair
{
public string Extension { get; } = extension;
public string ReceivedPath { get; } = receivedPath;
public string VerifiedPath { get; } = verifiedPath;
public bool IsText { get; } = FileExtensions.IsTextExtension(extension);
public FilePair(string extension, string receivedPath, string verifiedPath)
{
Guard.AgainstBadExtension(extension);
Extension = extension;
ReceivedPath = receivedPath;
VerifiedPath = verifiedPath;
IsText = FileExtensions.IsTextExtension(extension);
}

public string Extension { get; }
public string ReceivedPath { get; }
public string VerifiedPath { get; }
public bool IsText { get; }
}
5 changes: 5 additions & 0 deletions src/Verify/Guard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,10 @@ public static void AgainstBadExtension(string value, [CallerArgumentExpression("
{
throw new ArgumentException("Must not start with a period ('.').", argumentName);
}

if (value.Contains('\\') || value.Contains('/'))
{
throw new ArgumentException("Must not contain a directory separator.", argumentName);
}
}
}
1 change: 1 addition & 0 deletions src/Verify/Verifier/InnerVerifier_Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public Task<VerifyResult> VerifyStream(Stream? stream, object? info) =>

public async Task<VerifyResult> VerifyStream(Stream? stream, string extension, object? info)
{
Guard.AgainstBadExtension(extension);
if (stream is null)
{
if (info is null)
Expand Down

0 comments on commit 0b9a55b

Please sign in to comment.