Created
October 12, 2015 09:36
-
-
Save sumerman/b68128e09d1545cea981 to your computer and use it in GitHub Desktop.
Escape shell arguments in elixir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Shell do | |
def escape_value(value), do: escape_value(value, "") | |
defp escape_value("", res), do: "\"#{res}\"" | |
defp escape_value("\"" <> value, res), do: escape_value(value, res <> "\\\"") | |
defp escape_value("\\" <> value, res), do: escape_value(value, res <> "\\\\") | |
defp escape_value(<<char :: utf8, rest :: binary>>, res), | |
do: escape_value(rest, res <> <<char>>) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment