3
3
using System . Text . RegularExpressions ;
4
4
using System . Threading . Tasks ;
5
5
using Avalonia . Compatibility ;
6
- using Avalonia . Metadata ;
7
6
8
7
namespace Avalonia . Platform . Storage . FileIO ;
9
8
@@ -44,7 +43,8 @@ private static bool Exec(string urlOrFile)
44
43
{
45
44
// If no associated application/json MimeType is found xdg-open opens return error
46
45
// but it tries to open it anyway using the console editor (nano, vim, other..)
47
- ShellExec ( $ "xdg-open { urlOrFile } ", waitForExit : false ) ;
46
+ var args = EscapeForShell ( urlOrFile ) ;
47
+ ShellExecRaw ( $ "xdg-open \\ \" { args } \\ \" ", waitForExit : false ) ;
48
48
return true ;
49
49
}
50
50
else if ( OperatingSystemEx . IsWindows ( ) || OperatingSystemEx . IsMacOS ( ) )
@@ -63,17 +63,18 @@ private static bool Exec(string urlOrFile)
63
63
return false ;
64
64
}
65
65
}
66
-
67
- private static void ShellExec ( string cmd , bool waitForExit = true )
66
+
67
+ private static string EscapeForShell ( string input ) => Regex
68
+ . Replace ( input , "(?=[`~!#&*()|;'<>])" , "\\ " )
69
+ . Replace ( "\" " , "\\ \\ \\ \" " ) ;
70
+
71
+ private static void ShellExecRaw ( string cmd , bool waitForExit = true )
68
72
{
69
- var escapedArgs = Regex . Replace ( cmd , "(?=[`~!#&*()|;'<>])" , "\\ " )
70
- . Replace ( "\" " , "\\ \\ \\ \" " ) ;
71
-
72
73
using ( var process = Process . Start (
73
74
new ProcessStartInfo
74
75
{
75
76
FileName = "/bin/sh" ,
76
- Arguments = $ "-c \" { escapedArgs } \" ",
77
+ Arguments = $ "-c \" { cmd } \" ",
77
78
RedirectStandardOutput = true ,
78
79
UseShellExecute = false ,
79
80
CreateNoWindow = true ,
0 commit comments