@@ -49,12 +49,33 @@ describe("splitMediaFromOutput", () => {
4949 it . each ( [
5050 [ "/Users/pete/My File.png" , "MEDIA:/Users/pete/My File.png" ] ,
5151 [ "/Users/pete/My File.png" , 'MEDIA:"/Users/pete/My File.png"' ] ,
52+ [
53+ "/Users/pete/My Files/Project Assets/render final.png" ,
54+ "MEDIA:/Users/pete/My Files/Project Assets/render final.png" ,
55+ ] ,
56+ [
57+ "/Users/pete/My Files/Project Assets/render final.png" ,
58+ 'MEDIA:"/Users/pete/My Files/Project Assets/render final.png"' ,
59+ ] ,
60+ [ "/tmp/album.v1/photo.png copy.png" , "MEDIA:/tmp/album.v1/photo.png copy.png" ] ,
5261 [ "./screenshots/image.png" , "MEDIA:./screenshots/image.png" ] ,
5362 [ "media/inbound/image.png" , "MEDIA:media/inbound/image.png" ] ,
5463 [ "./screenshot.png" , " MEDIA:./screenshot.png" ] ,
5564 [ "~/Pictures/My File.png" , "MEDIA:~/Pictures/My File.png" ] ,
5665 [ "~/.openclaw/media/browser/snap.png" , "MEDIA:~/.openclaw/media/browser/snap.png" ] ,
5766 [ "C:\\Users\\pete\\Pictures\\snap.png" , "MEDIA:C:\\Users\\pete\\Pictures\\snap.png" ] ,
67+ [
68+ "C:\\Users\\First Last\\workspace\\shot.png" ,
69+ "MEDIA:C:\\Users\\First Last\\workspace\\shot.png" ,
70+ ] ,
71+ [
72+ "C:\\Users\\First Last\\workspace\\shot.png" ,
73+ "MEDIA:C:\\Users\\First Last\\workspace\\shot.png" ,
74+ ] ,
75+ [
76+ "\\\\server\\My Files\\Project Assets\\render final.png" ,
77+ "MEDIA:\\\\server\\My Files\\Project Assets\\render final.png" ,
78+ ] ,
5879 [ "/tmp/tts-fAJy8C/voice-1770246885083.opus" , "MEDIA:/tmp/tts-fAJy8C/voice-1770246885083.opus" ] ,
5980 [ "image.png" , "MEDIA:image.png" ] ,
6081 [
@@ -74,16 +95,56 @@ describe("splitMediaFromOutput", () => {
7495 expectAcceptedMediaPathCase ( expectedPath , input ) ;
7596 } ) ;
7697
98+ it . each ( [
99+ [ "MEDIA:/tmp/a.png /tmp/b.png" , [ "/tmp/a.png" , "/tmp/b.png" ] ] ,
100+ [ "MEDIA:media/a.png media/b.png" , [ "media/a.png" , "media/b.png" ] ] ,
101+ [ "MEDIA:/tmp/a.png media/b.png" , [ "/tmp/a.png" , "media/b.png" ] ] ,
102+ [ "MEDIA:./a.png ./b.png" , [ "./a.png" , "./b.png" ] ] ,
103+ [ "MEDIA:/tmp/a.png https://example.com/b.png" , [ "/tmp/a.png" , "https://example.com/b.png" ] ] ,
104+ [
105+ "MEDIA:C:\\Users\\First Last\\workspace\\shot.png D:\\Other User\\second.png" ,
106+ [ "C:\\Users\\First Last\\workspace\\shot.png" , "D:\\Other User\\second.png" ] ,
107+ ] ,
108+ [
109+ "MEDIA:C:\\Users\\First Last\\workspace\\shot.png media/second.png" ,
110+ [ "C:\\Users\\First Last\\workspace\\shot.png" , "media/second.png" ] ,
111+ ] ,
112+ [
113+ "MEDIA:/tmp/project screenshots/shot.png media\\second.png" ,
114+ [ "/tmp/project screenshots/shot.png" , "media\\second.png" ] ,
115+ ] ,
116+ [
117+ "MEDIA:/tmp/project screenshots/shot.png file:///tmp/second.png" ,
118+ [ "/tmp/project screenshots/shot.png" , "/tmp/second.png" ] ,
119+ ] ,
120+ [ "MEDIA:C:\\Users\\First Last\\..\\secret.png D:\\safe\\second.png" , [ "D:\\safe\\second.png" ] ] ,
121+ [ "MEDIA:/tmp/project screenshots/../../.env /tmp/safe/second.png" , [ "/tmp/safe/second.png" ] ] ,
122+ ] as const ) ( "keeps separate media items on one directive line: %s" , ( input , mediaUrls ) => {
123+ expectParsedMediaOutputCase ( input , { mediaUrls : [ ...mediaUrls ] } ) ;
124+ } ) ;
125+
77126 it . each ( [
78127 "MEDIA:../../../etc/passwd" ,
79128 "MEDIA:../../.env" ,
80129 "MEDIA:~user/Pictures/My File.png" ,
81130 "MEDIA:~/Pictures/../../.ssh/id_rsa" ,
82131 "MEDIA:./foo/../../../etc/shadow" ,
132+ "MEDIA:C:\\Users\\First Last\\..\\secret.png" ,
133+ "MEDIA:/tmp/project screenshots/../../.env" ,
83134 ] as const ) ( "rejects traversal and unsupported home-dir path: %s" , ( input ) => {
84135 expectRejectedMediaPathCase ( input ) ;
85136 } ) ;
86137
138+ it ( "does not absorb an unsafe remote URL into a spaced local media path" , ( ) => {
139+ expectParsedMediaOutputCase (
140+ "MEDIA:C:\\Users\\First Last\\workspace\\shot.png https://127.0.0.1/secret.png" ,
141+ {
142+ mediaUrls : [ "C:\\Users\\First Last\\workspace\\shot.png" ] ,
143+ text : "https://127.0.0.1/secret.png" ,
144+ } ,
145+ ) ;
146+ } ) ;
147+
87148 it . each ( [
88149 "MEDIA:http://example.com/a.png" ,
89150 "MEDIA:https://intranet/a.png" ,
0 commit comments