diff --git a/ChatGPTExport/Assets/ExistingAssetLocator.cs b/ChatGPTExport/Assets/ExistingAssetLocator.cs index 1d56f6f..53c8a2c 100644 --- a/ChatGPTExport/Assets/ExistingAssetLocator.cs +++ b/ChatGPTExport/Assets/ExistingAssetLocator.cs @@ -25,7 +25,17 @@ public void Add(string newFile) public string? GetMarkdownMediaAsset(AssetRequest assetRequest) { - // it may already exist in the destination directory from a previous export + var invalidChars = fileSystem.Path.GetInvalidFileNameChars() + .Concat(new[] { '*', '?', fileSystem.Path.DirectorySeparatorChar, fileSystem.Path.AltDirectorySeparatorChar }) + .Distinct() + .ToArray(); + + if (assetRequest.SearchPattern.IndexOfAny(invalidChars) >= 0) + { + return null; + } + + // it may already exist in the destination directory from a previous export var destinationMatches = GetCachedDestinationFiles(assetRequest.SearchPattern).ToList(); if (destinationMatches.Count == 0) { diff --git a/ChatGTPExportTests/Assets/ExistingAssetLocatorTests.cs b/ChatGTPExportTests/Assets/ExistingAssetLocatorTests.cs new file mode 100644 index 0000000..8eae3ee --- /dev/null +++ b/ChatGTPExportTests/Assets/ExistingAssetLocatorTests.cs @@ -0,0 +1,47 @@ +using ChatGPTExport.Assets; +using System.IO.Abstractions.TestingHelpers; + +namespace ChatGTPExportTests.Assets +{ + public class ExistingAssetLocatorTests + { + [Theory] + [InlineData("image*")] + [InlineData("image?")] + [InlineData("image/")] + [InlineData("image\\")] + [InlineData("invali