File tree Expand file tree Collapse file tree
testsuite/tests/lib-filename Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -617,6 +617,10 @@ ___________
617617 from a DLL
618618 (Xavier Leroy, review by Miod Vallat)
619619
620+ - #13417: `Filename.quote_command`: fix handling of forward slashes in program
621+ path under Win32.
622+ (Nicolás Ojeda Bär, review by David Allsopp and Damien Doligez)
623+
620624OCaml 5.2.0 (13 May 2024)
621625-------------------------
622626
Original file line number Diff line number Diff line change @@ -219,6 +219,13 @@ Quoting commands for execution by cmd.exe is difficult.
219219 s;
220220 Buffer. contents b
221221 let quote_cmd_filename f =
222+ (* In cmd.exe, forward slashes in the program path (argument 0) are
223+ interpreted as introducing a flag. *)
224+ let f =
225+ if String. contains f '/' then
226+ String. map (function '/' -> '\\' | c -> c) f
227+ else f
228+ in
222229 if String. exists (function '\"' | '%' -> true | _ -> false ) f then
223230 failwith (" Filename.quote_command: bad file name " ^ f)
224231 else if String. contains f ' ' then
Original file line number Diff line number Diff line change @@ -53,16 +53,17 @@ let cat_file f =
5353let myecho =
5454 Filename. concat Filename. current_dir_name " my echo.exe"
5555
56- let run ?stdin ?stdout ?stderr args =
56+ let run prog ?stdin ?stdout ?stderr args =
5757 flush Stdlib. stdout;
5858 let rc =
59- Sys. command (Filename. quote_command myecho ?stdin ?stdout ?stderr args) in
59+ Sys. command (Filename. quote_command prog ?stdin ?stdout ?stderr args) in
6060 if rc > 0 then begin
61- printf " !!! my echo failed\n " ;
61+ printf " !!! %s failed\n " prog ;
6262 exit 2
6363 end
6464
6565let _ =
66+ let run = run myecho in
6667 copy_file " myecho.exe" " my echo.exe" ;
6768 printf " -------- Spaces\n " ;
6869 run [" Lorem ipsum dolor" ; " sit amet," ; " consectetur adipiscing elit," ];
@@ -100,3 +101,7 @@ let _ =
100101 " in voluptate" ; " -out" ; " velit esse cillum" ; " -err" ; " dolore" ];
101102 cat_file " my file.tmp" ; Sys. remove " my file.tmp" ;
102103 Sys. remove " my echo.exe"
104+
105+ let _ =
106+ printf " -------- Forward slashes in program position\n " ;
107+ run " ./myecho.exe" [" alea iacta est" ]
Original file line number Diff line number Diff line change @@ -36,3 +36,5 @@ argv[4] = {|in reprehenderit|}
3636argv[5] = {|in voluptate|}
3737argv[7] = {|velit esse cillum|}
3838argv[9] = {|dolore|}
39+ -------- Forward slashes in program position
40+ argv[1] = {|alea iacta est|}
You can’t perform that action at this time.
0 commit comments