tazel
A build system for C, C++, Objective-C, Objective-C++ and Zig, with C# project files.
Clonegit clone https://git.progmasoft.com/tazel
Keep what a test writes inside its temporary module
- Commit
9b4858da9a79482802437e38109686a091f85d76- Author
- Leitwolf11 ·
- Parents
78b26633272a
Changes
tests/Progmasoft.Tazel.Tests/TemporaryModule.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/Progmasoft.Tazel.Tests/TemporaryModule.cs b/tests/Progmasoft.Tazel.Tests/TemporaryModule.cs index 029f185..d76e37b 100644 --- a/tests/Progmasoft.Tazel.Tests/TemporaryModule.cs +++ b/tests/Progmasoft.Tazel.Tests/TemporaryModule.cs @@ -31,7 +31,13 @@ internal sealed class TemporaryModule : IDisposable /// <summary>Writes <paramref name="text"/> to <paramref name="relative"/>, making its directories.</summary> public TemporaryModule Write(string relative, string text) { - var path = Path.Combine(Root, relative); + // A test writes inside its module only. + var path = Path.GetFullPath(Path.Combine(Root, relative)); + if (!path.StartsWith(Path.GetFullPath(Root) + Path.DirectorySeparatorChar, StringComparison.Ordinal)) + { + throw new ArgumentException($"'{relative}' is outside the module", nameof(relative)); + } + Directory.CreateDirectory(Path.GetDirectoryName(path)!); File.WriteAllText(path, text); return this;