@@ -55,23 +55,27 @@ public override async Task<int> ExecuteAsync(CommandContext context, Settings se
5555 }
5656 catch ( OpenApiUnsupportedSpecVersionException exception )
5757 {
58- AnsiConsole . MarkupLine ( $ "{ Crlf } [red]Error:{ Crlf } { exception . Message } [/]") ;
58+ var escapedMessage = exception . Message . Replace ( "[" , "[[" ) . Replace ( "]" , "]]" ) ;
59+ AnsiConsole . MarkupLine ( $ "{ Crlf } [red]Error:{ Crlf } { escapedMessage } [/]") ;
5960 AnsiConsole . MarkupLine (
6061 $ "{ Crlf } [yellow]Tips:{ Crlf } " +
6162 $ "Consider using the --skip-validation argument.{ Crlf } " +
6263 $ "In some cases, the features that are specific to the " +
6364 $ "unsupported versions of OpenAPI specifications aren't really used.{ Crlf } " +
64- $ "This tool uses NSwag libraries to parse the OpenAPI document and " +
65- $ "Microsoft.OpenApi libraries for validation.{ Crlf } { Crlf } [/]") ;
65+ $ "This tool uses Microsoft.OpenApi libraries for both parsing and validation.{ Crlf } { Crlf } [/]") ;
6666 return exception . HResult ;
6767 }
6868 catch ( Exception exception )
6969 {
7070 if ( exception is not OpenApiValidationException )
7171 {
72- AnsiConsole . MarkupLine ( $ "{ Crlf } [red]Error:{ Crlf } { exception . Message } [/]") ;
72+ // Escape markup characters in exception messages
73+ var escapedMessage = exception . Message . Replace ( "[" , "[[" ) . Replace ( "]" , "]]" ) ;
74+ var escapedStackTrace = exception . StackTrace ? . Replace ( "[" , "[[" ) . Replace ( "]" , "]]" ) ?? "" ;
75+
76+ AnsiConsole . MarkupLine ( $ "{ Crlf } [red]Error:{ Crlf } { escapedMessage } [/]") ;
7377 AnsiConsole . MarkupLine ( $ "[red]Exception:{ Crlf } { exception . GetType ( ) } [/]") ;
74- AnsiConsole . MarkupLine ( $ "[yellow]Stack Trace:{ Crlf } { exception . StackTrace } [/]") ;
78+ AnsiConsole . MarkupLine ( $ "[yellow]Stack Trace:{ Crlf } { escapedStackTrace } [/]") ;
7579 }
7680
7781 await Analytics . LogError ( exception , settings ) ;
@@ -104,7 +108,8 @@ private static async Task AcquireAzureEntraIdToken(Settings settings)
104108 }
105109 catch ( Exception exception )
106110 {
107- AnsiConsole . MarkupLine ( $ "{ Crlf } [red]Error:{ Crlf } { exception . Message } [/]") ;
111+ var escapedMessage = exception . Message . Replace ( "[" , "[[" ) . Replace ( "]" , "]]" ) ;
112+ AnsiConsole . MarkupLine ( $ "{ Crlf } [red]Error:{ Crlf } { escapedMessage } [/]") ;
108113 }
109114 }
110115
@@ -158,7 +163,9 @@ private static void TryWriteLine(
158163 {
159164 try
160165 {
161- AnsiConsole . MarkupLine ( $ "[{ color } ]{ label } :{ Crlf } { error } { Crlf } [/]") ;
166+ // Escape markup characters in the error message to prevent markup interpretation
167+ var escapedError = error . ToString ( ) . Replace ( "[" , "[[" ) . Replace ( "]" , "]]" ) ;
168+ AnsiConsole . MarkupLine ( $ "[{ color } ]{ label } :{ Crlf } { escapedError } { Crlf } [/]") ;
162169 }
163170 catch
164171 {
@@ -253,7 +260,9 @@ private static void DisplayResults(GeneratorResult result, TimeSpan elapsed, Set
253260 < 1024 * 1024 => $ "{ fileSize / 1024.0 : F1} KB",
254261 _ => $ "{ fileSize / ( 1024.0 * 1024.0 ) : F1} MB"
255262 } ;
256- AnsiConsole . MarkupLine ( $ " 📝 [cyan]{ file . Filename } [/] [dim]({ fileSizeText } )[/]") ;
263+ // Escape markup characters in filename
264+ var escapedFilename = file . Filename . Replace ( "[" , "[[" ) . Replace ( "]" , "]]" ) ;
265+ AnsiConsole . MarkupLine ( $ " 📝 [cyan]{ escapedFilename } [/] [dim]({ fileSizeText } )[/]") ;
257266 }
258267 }
259268 else
0 commit comments