Shell escape dollar signs

But allow for shell expansion using curly braces e.g. ${PWD}
This commit is contained in:
Stanko K.R
2023-03-22 16:57:17 +01:00
parent 60a19f0b30
commit 3ab16c8994
3 changed files with 31 additions and 1 deletions

View File

@@ -49,5 +49,16 @@ class UtilsTest < ActiveSupport::TestCase
test "escape_shell_value" do
assert_equal "\"foo\"", Mrsk::Utils.escape_shell_value("foo")
assert_equal "\"\\`foo\\`\"", Mrsk::Utils.escape_shell_value("`foo`")
assert_equal "\"${PWD}\"", Mrsk::Utils.escape_shell_value("${PWD}")
assert_equal "\"${cat /etc/hostname}\"", Mrsk::Utils.escape_shell_value("${cat /etc/hostname}")
assert_equal "\"\\${PWD]\"", Mrsk::Utils.escape_shell_value("${PWD]")
assert_equal "\"\\$(PWD)\"", Mrsk::Utils.escape_shell_value("$(PWD)")
assert_equal "\"\\$PWD\"", Mrsk::Utils.escape_shell_value("$PWD")
assert_equal "\"^(https?://)www.example.com/(.*)\\$\"",
Mrsk::Utils.escape_shell_value("^(https?://)www.example.com/(.*)$")
assert_equal "\"https://example.com/\\$2\"",
Mrsk::Utils.escape_shell_value("https://example.com/$2")
end
end