Merge pull request #15 from StevanFreeborn/copilot/fix-escape-markup-console

This commit is contained in:
Stevan Freeborn
2025-10-09 19:09:25 -05:00
committed by GitHub
2 changed files with 22 additions and 3 deletions
@@ -53,7 +53,7 @@ internal sealed class DefaultCommand(
if (_fileSystem.File.Exists(settings.Stream) is false) if (_fileSystem.File.Exists(settings.Stream) is false)
{ {
return ValidationResult.Error($"The specified stream file '{settings.Stream}' does not exist."); return ValidationResult.Error($"The specified stream file '{settings.Stream.EscapeMarkup()}' does not exist.");
} }
var fileExtension = _fileSystem.Path.GetExtension(settings.Stream).ToUpperInvariant(); var fileExtension = _fileSystem.Path.GetExtension(settings.Stream).ToUpperInvariant();
@@ -68,7 +68,7 @@ internal sealed class DefaultCommand(
public override async Task<int> ExecuteAsync(CommandContext context, Settings settings) public override async Task<int> ExecuteAsync(CommandContext context, Settings settings)
{ {
_console.MarkupLine($"[blue]Processing stream:[/] {settings.Stream}"); _console.MarkupLine($"[blue]Processing stream:[/] {settings.Stream.EscapeMarkup()}");
var videoStream = _fileSystem.File.OpenRead(settings.Stream); var videoStream = _fileSystem.File.OpenRead(settings.Stream);
Stream? audioStream = null; Stream? audioStream = null;
@@ -147,7 +147,7 @@ internal sealed class DefaultCommand(
}); });
var directoryUri = new Uri(outputDirectoryPath).AbsoluteUri; var directoryUri = new Uri(outputDirectoryPath).AbsoluteUri;
var panel = new Panel($"[blue link={directoryUri}]{artifactsOutputDirectory}[/]") var panel = new Panel($"[blue link={directoryUri}]{artifactsOutputDirectory.EscapeMarkup()}[/]")
{ {
Header = new PanelHeader($"[blue]Shorts created[/] [green]successfully![/]") Header = new PanelHeader($"[blue]Shorts created[/] [green]successfully![/]")
}; };
@@ -0,0 +1,19 @@
namespace StreamShorts.Console.Tests.Unit.Commands;
using Spectre.Console;
public class DefaultCommandTests
{
[Theory]
[InlineData("file[with]brackets.mp4", "file[[with]]brackets.mp4")]
[InlineData("normal-file.mp4", "normal-file.mp4")]
[InlineData("file_with_underscores.mp4", "file_with_underscores.mp4")]
[InlineData("file with spaces.mp4", "file with spaces.mp4")]
[InlineData("[brackets].mp4", "[[brackets]].mp4")]
public void EscapeMarkup_WhenCalledWithVariousInputs_ItShouldProperlyEscapeSquareBrackets(string input, string expected)
{
var result = input.EscapeMarkup();
result.Should().Be(expected);
}
}