From 21d1df824f54d311d2ce9e3b9e60d208687f370b Mon Sep 17 00:00:00 2001 From: Jonas Kamsker <11245306+JKamsker@users.noreply.github.com> Date: Tue, 4 Jan 2022 16:05:40 +0100 Subject: [PATCH 1/2] Added string escape for DemuxConcatArgument Fixes issue when source files have a ``'`` in their path --- FFMpegCore/FFMpeg/Arguments/DemuxConcatArgument.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/FFMpegCore/FFMpeg/Arguments/DemuxConcatArgument.cs b/FFMpegCore/FFMpeg/Arguments/DemuxConcatArgument.cs index c672c74..47564f9 100644 --- a/FFMpegCore/FFMpeg/Arguments/DemuxConcatArgument.cs +++ b/FFMpegCore/FFMpeg/Arguments/DemuxConcatArgument.cs @@ -16,8 +16,17 @@ public class DemuxConcatArgument : IInputArgument public readonly IEnumerable Values; public DemuxConcatArgument(IEnumerable values) { - Values = values.Select(value => $"file '{value}'"); + Values = values.Select(value => $"file '{Escape(value)}'"); } + + /// + /// Thanks slhck + /// https://superuser.com/a/787651/1089628 + /// + /// + /// + private string Escape(string value) => value.Replace("'", @"'\''"); + private readonly string _tempFileName = Path.Combine(GlobalFFOptions.Current.TemporaryFilesFolder, $"concat_{Guid.NewGuid()}.txt"); public void Pre() => File.WriteAllLines(_tempFileName, Values); From e79448df485b017a7d5fde49efd17b38e98df4c2 Mon Sep 17 00:00:00 2001 From: Jonas Kamsker Date: Tue, 4 Jan 2022 17:47:10 +0100 Subject: [PATCH 2/2] Added unit test --- FFMpegCore.Test/FFMpegArgumentProcessorTest.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/FFMpegCore.Test/FFMpegArgumentProcessorTest.cs b/FFMpegCore.Test/FFMpegArgumentProcessorTest.cs index dc65489..8443d0d 100644 --- a/FFMpegCore.Test/FFMpegArgumentProcessorTest.cs +++ b/FFMpegCore.Test/FFMpegArgumentProcessorTest.cs @@ -1,6 +1,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using FluentAssertions; using System.Reflection; +using FFMpegCore.Arguments; namespace FFMpegCore.Test { @@ -86,5 +87,12 @@ FFMpegArgumentProcessor CreateArgumentProcessor() => FFMpegArguments var options2 = processor2.GetConfiguredOptions(null); options2.WorkingDirectory.Should().Be(globalWorkingDir); } + + [TestMethod] + public void Concat_Escape() + { + var arg = new DemuxConcatArgument(new[] { @"Heaven's River\05 - Investigation.m4b" }); + arg.Values.Should().BeEquivalentTo(new[] { @"file 'Heaven'\''s River\05 - Investigation.m4b'" }); + } } } \ No newline at end of file