Skip to content

Commit 0b9a55b

Browse files
committed
more AgainstBadExtension
1 parent 49d0af1 commit 0b9a55b

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

src/Verify/FilePair.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
namespace VerifyTests;
22

3-
public readonly struct FilePair(string extension, string receivedPath, string verifiedPath)
3+
public readonly struct FilePair
44
{
5-
public string Extension { get; } = extension;
6-
public string ReceivedPath { get; } = receivedPath;
7-
public string VerifiedPath { get; } = verifiedPath;
8-
public bool IsText { get; } = FileExtensions.IsTextExtension(extension);
5+
public FilePair(string extension, string receivedPath, string verifiedPath)
6+
{
7+
Guard.AgainstBadExtension(extension);
8+
Extension = extension;
9+
ReceivedPath = receivedPath;
10+
VerifiedPath = verifiedPath;
11+
IsText = FileExtensions.IsTextExtension(extension);
12+
}
13+
14+
public string Extension { get; }
15+
public string ReceivedPath { get; }
16+
public string VerifiedPath { get; }
17+
public bool IsText { get; }
918
}

src/Verify/Guard.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,10 @@ public static void AgainstBadExtension(string value, [CallerArgumentExpression("
144144
{
145145
throw new ArgumentException("Must not start with a period ('.').", argumentName);
146146
}
147+
148+
if (value.Contains('\\') || value.Contains('/'))
149+
{
150+
throw new ArgumentException("Must not contain a directory separator.", argumentName);
151+
}
147152
}
148153
}

src/Verify/Verifier/InnerVerifier_Stream.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public Task<VerifyResult> VerifyStream(Stream? stream, object? info) =>
7373

7474
public async Task<VerifyResult> VerifyStream(Stream? stream, string extension, object? info)
7575
{
76+
Guard.AgainstBadExtension(extension);
7677
if (stream is null)
7778
{
7879
if (info is null)

0 commit comments

Comments
 (0)