|
9 | 9 | -export([path_split/1]).
|
10 | 10 | -export([urlsplit/1, urlsplit_path/1, urlunsplit/1, urlunsplit_path/1]).
|
11 | 11 | -export([parse_header/1]).
|
12 |
| --export([shell_quote/1, cmd/1, cmd_string/1, cmd_port/2, cmd_status/1, cmd_status/2]). |
13 | 12 | -export([record_to_proplist/2, record_to_proplist/3]).
|
14 | 13 | -export([safe_relative_path/1, partition/2]).
|
15 | 14 | -export([parse_qvalues/1, pick_accepted_encodings/3]).
|
@@ -102,52 +101,6 @@ safe_relative_path(P, Acc) ->
|
102 | 101 | safe_relative_path(Rest, [Part | Acc])
|
103 | 102 | end.
|
104 | 103 |
|
105 |
| -%% @spec shell_quote(string()) -> string() |
106 |
| -%% @doc Quote a string according to UNIX shell quoting rules, returns a string |
107 |
| -%% surrounded by double quotes. |
108 |
| -shell_quote(L) -> |
109 |
| - shell_quote(L, [$\"]). |
110 |
| - |
111 |
| -%% @spec cmd_port([string()], Options) -> port() |
112 |
| -%% @doc open_port({spawn, mochiweb_util:cmd_string(Argv)}, Options). |
113 |
| -cmd_port(Argv, Options) -> |
114 |
| - open_port({spawn, cmd_string(Argv)}, Options). |
115 |
| - |
116 |
| -%% @spec cmd([string()]) -> string() |
117 |
| -%% @doc os:cmd(cmd_string(Argv)). |
118 |
| -cmd(Argv) -> |
119 |
| - os:cmd(cmd_string(Argv)). |
120 |
| - |
121 |
| -%% @spec cmd_string([string()]) -> string() |
122 |
| -%% @doc Create a shell quoted command string from a list of arguments. |
123 |
| -cmd_string(Argv) -> |
124 |
| - string:join([shell_quote(X) || X <- Argv], " "). |
125 |
| - |
126 |
| -%% @spec cmd_status([string()]) -> {ExitStatus::integer(), Stdout::binary()} |
127 |
| -%% @doc Accumulate the output and exit status from the given application, |
128 |
| -%% will be spawned with cmd_port/2. |
129 |
| -cmd_status(Argv) -> |
130 |
| - cmd_status(Argv, []). |
131 |
| - |
132 |
| -%% @spec cmd_status([string()], [atom()]) -> {ExitStatus::integer(), Stdout::binary()} |
133 |
| -%% @doc Accumulate the output and exit status from the given application, |
134 |
| -%% will be spawned with cmd_port/2. |
135 |
| -cmd_status(Argv, Options) -> |
136 |
| - Port = cmd_port(Argv, [exit_status, stderr_to_stdout, |
137 |
| - use_stdio, binary | Options]), |
138 |
| - try cmd_loop(Port, []) |
139 |
| - after catch port_close(Port) |
140 |
| - end. |
141 |
| - |
142 |
| -%% @spec cmd_loop(port(), list()) -> {ExitStatus::integer(), Stdout::binary()} |
143 |
| -%% @doc Accumulate the output and exit status from a port. |
144 |
| -cmd_loop(Port, Acc) -> |
145 |
| - receive |
146 |
| - {Port, {exit_status, Status}} -> |
147 |
| - {Status, iolist_to_binary(lists:reverse(Acc))}; |
148 |
| - {Port, {data, Data}} -> |
149 |
| - cmd_loop(Port, [Data | Acc]) |
150 |
| - end. |
151 | 104 |
|
152 | 105 | %% @spec join([iolist()], iolist()) -> iolist()
|
153 | 106 | %% @doc Join a list of strings or binaries together with the given separator
|
@@ -406,15 +359,6 @@ record_to_proplist(Record, Fields, TypeKey)
|
406 | 359 | when tuple_size(Record) - 1 =:= length(Fields) ->
|
407 | 360 | lists:zip([TypeKey | Fields], tuple_to_list(Record)).
|
408 | 361 |
|
409 |
| - |
410 |
| -shell_quote([], Acc) -> |
411 |
| - lists:reverse([$\" | Acc]); |
412 |
| -shell_quote([C | Rest], Acc) when C =:= $\" orelse C =:= $\` orelse |
413 |
| - C =:= $\\ orelse C =:= $\$ -> |
414 |
| - shell_quote(Rest, [C, $\\ | Acc]); |
415 |
| -shell_quote([C | Rest], Acc) -> |
416 |
| - shell_quote(Rest, [C | Acc]). |
417 |
| - |
418 | 362 | %% @spec parse_qvalues(string()) -> [qvalue()] | invalid_qvalue_string
|
419 | 363 | %% @type qvalue() = {media_type() | encoding() , float()}.
|
420 | 364 | %% @type media_type() = string().
|
@@ -608,60 +552,6 @@ record_to_proplist_test() ->
|
608 | 552 | typekey)),
|
609 | 553 | ok.
|
610 | 554 |
|
611 |
| -shell_quote_test() -> |
612 |
| - ?assertEqual( |
613 |
| - "\"foo \\$bar\\\"\\`' baz\"", |
614 |
| - shell_quote("foo $bar\"`' baz")), |
615 |
| - ok. |
616 |
| - |
617 |
| -cmd_port_test_spool(Port, Acc) -> |
618 |
| - receive |
619 |
| - {Port, eof} -> |
620 |
| - Acc; |
621 |
| - {Port, {data, {eol, Data}}} -> |
622 |
| - cmd_port_test_spool(Port, ["\n", Data | Acc]); |
623 |
| - {Port, Unknown} -> |
624 |
| - throw({unknown, Unknown}) |
625 |
| - after 1000 -> |
626 |
| - throw(timeout) |
627 |
| - end. |
628 |
| - |
629 |
| -cmd_port_test() -> |
630 |
| - Port = cmd_port(["echo", "$bling$ `word`!"], |
631 |
| - [eof, stream, {line, 4096}]), |
632 |
| - Res = try lists:append(lists:reverse(cmd_port_test_spool(Port, []))) |
633 |
| - after catch port_close(Port) |
634 |
| - end, |
635 |
| - self() ! {Port, wtf}, |
636 |
| - try cmd_port_test_spool(Port, []) |
637 |
| - catch throw:{unknown, wtf} -> ok |
638 |
| - end, |
639 |
| - try cmd_port_test_spool(Port, []) |
640 |
| - catch throw:timeout -> ok |
641 |
| - end, |
642 |
| - ?assertEqual( |
643 |
| - "$bling$ `word`!\n", |
644 |
| - Res). |
645 |
| - |
646 |
| -cmd_test() -> |
647 |
| - ?assertEqual( |
648 |
| - "$bling$ `word`!\n", |
649 |
| - cmd(["echo", "$bling$ `word`!"])), |
650 |
| - ok. |
651 |
| - |
652 |
| -cmd_string_test() -> |
653 |
| - ?assertEqual( |
654 |
| - "\"echo\" \"\\$bling\\$ \\`word\\`!\"", |
655 |
| - cmd_string(["echo", "$bling$ `word`!"])), |
656 |
| - ok. |
657 |
| - |
658 |
| -cmd_status_test() -> |
659 |
| - ?assertEqual( |
660 |
| - {0, <<"$bling$ `word`!\n">>}, |
661 |
| - cmd_status(["echo", "$bling$ `word`!"])), |
662 |
| - ok. |
663 |
| - |
664 |
| - |
665 | 555 | parse_header_test() ->
|
666 | 556 | ?assertEqual(
|
667 | 557 | {"multipart/form-data", [{"boundary", "AaB03x"}]},
|
|
0 commit comments