From 0b9a55b4e47ccf90a59bc377f28d0a8c56ee8952 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Fri, 14 Jun 2024 19:39:22 +1000 Subject: [PATCH] more AgainstBadExtension --- src/Verify/FilePair.cs | 19 ++++++++++++++----- src/Verify/Guard.cs | 5 +++++ src/Verify/Verifier/InnerVerifier_Stream.cs | 1 + 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Verify/FilePair.cs b/src/Verify/FilePair.cs index 7ef9ca2002..ea01bb43ee 100644 --- a/src/Verify/FilePair.cs +++ b/src/Verify/FilePair.cs @@ -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; } } \ No newline at end of file diff --git a/src/Verify/Guard.cs b/src/Verify/Guard.cs index 226801e0d8..2a7844663c 100644 --- a/src/Verify/Guard.cs +++ b/src/Verify/Guard.cs @@ -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); + } } } \ No newline at end of file diff --git a/src/Verify/Verifier/InnerVerifier_Stream.cs b/src/Verify/Verifier/InnerVerifier_Stream.cs index 815349bac5..f3909fe5c1 100644 --- a/src/Verify/Verifier/InnerVerifier_Stream.cs +++ b/src/Verify/Verifier/InnerVerifier_Stream.cs @@ -73,6 +73,7 @@ public Task VerifyStream(Stream? stream, object? info) => public async Task VerifyStream(Stream? stream, string extension, object? info) { + Guard.AgainstBadExtension(extension); if (stream is null) { if (info is null)