{"action":"created","issue":{"url":"https://api.github.com/repos/ocaml/ocaml/issues/1492","repository_url":"https://api.github.com/repos/ocaml/ocaml","labels_url":"https://api.github.com/repos/ocaml/ocaml/issues/1492/labels{/name}","comments_url":"https://api.github.com/repos/ocaml/ocaml/issues/1492/comments","events_url":"https://api.github.com/repos/ocaml/ocaml/issues/1492/events","html_url":"https://github.com/ocaml/ocaml/pull/1492","id":276835887,"node_id":"MDExOlB1bGxSZXF1ZXN0MTU0Njg1NDA1","number":1492,"title":"Add Filename.quote_command function","user":{"login":"xavierleroy","id":3845810,"node_id":"MDQ6VXNlcjM4NDU4MTA=","avatar_url":"https://avatars0.githubusercontent.com/u/3845810?v=4","gravatar_id":"","url":"https://api.github.com/users/xavierleroy","html_url":"https://github.com/xavierleroy","followers_url":"https://api.github.com/users/xavierleroy/followers","following_url":"https://api.github.com/users/xavierleroy/following{/other_user}","gists_url":"https://api.github.com/users/xavierleroy/gists{/gist_id}","starred_url":"https://api.github.com/users/xavierleroy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xavierleroy/subscriptions","organizations_url":"https://api.github.com/users/xavierleroy/orgs","repos_url":"https://api.github.com/users/xavierleroy/repos","events_url":"https://api.github.com/users/xavierleroy/events{/privacy}","received_events_url":"https://api.github.com/users/xavierleroy/received_events","type":"User","site_admin":false},"labels":[{"id":851463272,"node_id":"MDU6TGFiZWw4NTE0NjMyNzI=","url":"https://api.github.com/repos/ocaml/ocaml/labels/high-priority","name":"high-priority","color":"fbca04","default":false},{"id":272541344,"node_id":"MDU6TGFiZWwyNzI1NDEzNDQ=","url":"https://api.github.com/repos/ocaml/ocaml/labels/stdlib","name":"stdlib","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":16,"created_at":"2017-11-26T16:10:40Z","updated_at":"2018-06-08T14:39:27Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/ocaml/ocaml/pulls/1492","html_url":"https://github.com/ocaml/ocaml/pull/1492","diff_url":"https://github.com/ocaml/ocaml/pull/1492.diff","patch_url":"https://github.com/ocaml/ocaml/pull/1492.patch"},"body":"As reported in [MPR#6107](https://caml.inria.fr/mantis/view.php?id=6107) and [MPR#7672](https://caml.inria.fr/mantis/view.php?id=7672), it is not easy to properly quote the command name and its arguments in a shell command executed through `Sys.command` or the `Unix.open_process*` functions.  For a POSIX shell it is enough to apply `Filename.quote` on every argument.  But for the Windows shell `cmd.exe`, additional quoting is required on top of that, as explained [here](https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/).\r\n\r\nThis pull requests grants the feature wish from [MPR#7672](https://caml.inria.fr/mantis/view.php?id=7672) by adding a `Filename.quote_command` function that takes a command and its arguments (as a list of strings) and produces a command line appropriately quoted for the shell that is going to parse and execute it.  \r\n\r\nDocumentation of `Sys.command`, `Unix.system` and `Unix.open_process*` was updated to encourage the use of `Filename.quote_command`.\r\n\r\n### Preventive FAQ\r\n\r\n**Q**: why `string list -> string` and not `string array -> string` for consistency with `Unix.exec`?\r\n\r\n**A**: it felt right.  MPR#7672 suggested `string list`.  It's easier to build a list (with `::` and `@`) than an array.  Perhaps it's `Unix.exec` that is wrong in its use of a `string array`.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/ocaml/ocaml/issues/comments/395781668","html_url":"https://github.com/ocaml/ocaml/pull/1492#issuecomment-395781668","issue_url":"https://api.github.com/repos/ocaml/ocaml/issues/1492","id":395781668,"node_id":"MDEyOklzc3VlQ29tbWVudDM5NTc4MTY2OA==","user":{"login":"xavierleroy","id":3845810,"node_id":"MDQ6VXNlcjM4NDU4MTA=","avatar_url":"https://avatars0.githubusercontent.com/u/3845810?v=4","gravatar_id":"","url":"https://api.github.com/users/xavierleroy","html_url":"https://github.com/xavierleroy","followers_url":"https://api.github.com/users/xavierleroy/followers","following_url":"https://api.github.com/users/xavierleroy/following{/other_user}","gists_url":"https://api.github.com/users/xavierleroy/gists{/gist_id}","starred_url":"https://api.github.com/users/xavierleroy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xavierleroy/subscriptions","organizations_url":"https://api.github.com/users/xavierleroy/orgs","repos_url":"https://api.github.com/users/xavierleroy/repos","events_url":"https://api.github.com/users/xavierleroy/events{/privacy}","received_events_url":"https://api.github.com/users/xavierleroy/received_events","type":"User","site_admin":false},"created_at":"2018-06-08T14:39:26Z","updated_at":"2018-06-08T14:39:26Z","author_association":"CONTRIBUTOR","body":"I closed this PR by accident.  Actually I meant to push a new implementation of `Filename.quote_command` that addresses most if not all of the problems discussed above.\r\n\r\nThe API is now\r\n```\r\n   Filename.quote_command cmd ?input ?output args\r\n```\r\nwith the command `cmd` separated from the list of arguments `args`, and `<` and `>` redirections expressed with optional arguments `?input` and `?output`, then properly encoded by `Filename.quote_command`.\r\n\r\nIn a nutshell, `args` is escaped as before, first using `Filename.quote`, then (under Win32) using `^` to quote characters that are special for cmd.exe.\r\n\r\nThe novelty is that, under Win32, `cmd` and the optional redirection files are checked for the absence of double-quote and percent characters (which we have problems quoting!), then quoted using double quotes.\r\n\r\nFinally, for good measure, the whole command line is wrapped in double quotes to please cmd.exe.\r\n"}}
{"actor":{"display_login":"xavierleroy"}}