Skip to content

Commit 955b904

Browse files
author
Hugo Heuzard
committed
fix quoting on windows+bash
1 parent aa77af8 commit 955b904

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/shell.ml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,26 @@ let is_simple_filename s =
2424
| 'a'..'z' | 'A'..'Z' | '0'..'9' | '.' | '-' | '/' | '_' | ':' | '@' | '+' | ',' -> loop (pos + 1)
2525
| _ -> false in
2626
loop 0
27+
28+
(*** Copied from ocaml/stdlib/filename.ml *)
29+
let generic_quote quotequote s =
30+
let l = String.length s in
31+
let b = Buffer.create (l + 20) in
32+
Buffer.add_char b '\'';
33+
for i = 0 to l - 1 do
34+
if s.[i] = '\''
35+
then Buffer.add_string b quotequote
36+
else Buffer.add_char b s.[i]
37+
done;
38+
Buffer.add_char b '\'';
39+
Buffer.contents b
40+
41+
let unix_quote = generic_quote "'\\''"
42+
2743
let quote_filename_if_needed s =
2844
if is_simple_filename s then s
29-
(* We should probably be using [Filename.unix_quote] except that function
30-
* isn't exported. Users on Windows will have to live with not being able to
31-
* install OCaml into c:\o'caml. Too bad. *)
32-
else if Sys.win32 then Printf.sprintf "'%s'" s
33-
else Filename.quote s
45+
else unix_quote s
46+
3447
let chdir dir =
3548
reset_filesys_cache ();
3649
Sys.chdir dir

0 commit comments

Comments
 (0)