This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change exec(args) to exec(shelljoin(string))
* fixes unicode problems on windows
- Loading branch information
Ransom Briggs
committed
Dec 2, 2015
1 parent
aae9bf3
commit 78869d7
Showing
2 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require "spec_helper" | ||
require "heroku/jsplugin" | ||
|
||
module Heroku | ||
describe JSPlugin do | ||
context "shellescape" do | ||
it "should to_s the arguments" do | ||
expect(Heroku::JSPlugin.shellescape(3)).to eq("3") | ||
end | ||
|
||
it "should return single quotes for an empty string" do | ||
expect(Heroku::JSPlugin.shellescape('')).to eq("''") | ||
end | ||
|
||
it "escape newlines properly" do | ||
expect(Heroku::JSPlugin.shellescape("\n")).to eq("'\n'") | ||
end | ||
|
||
it "escapes bad shell commands" do | ||
expect(Heroku::JSPlugin.shellescape("`$()|;&><'\"")).to eq("\\`\\$\\(\\)\\|\\;\\&\\>\\<\\'\\\"") | ||
end | ||
|
||
it "passes options through" do | ||
expect(Heroku::JSPlugin.shellescape("-f")).to eq("-f") | ||
end | ||
|
||
it "passes multi byte characters through" do | ||
expect(Heroku::JSPlugin.shellescape("あい")).to eq("あい") | ||
end | ||
|
||
it "passes ascci numbers and letters through without escaping" do | ||
expect(Heroku::JSPlugin.shellescape("Aa0")).to eq("Aa0") | ||
end | ||
|
||
it "passes multi byte characters through" do | ||
expect(Heroku::JSPlugin.shellescape("あい")).to eq("あい") | ||
end | ||
|
||
it "passes multi byte numbers through" do | ||
expect(Heroku::JSPlugin.shellescape("Ⅲ")).to eq("Ⅲ") | ||
end | ||
|
||
it "does not fail on things that cannot be converted to utf-8" do | ||
expected_bad_encoding = "\u0412".force_encoding("ASCII-8BIT") | ||
expected_bad_encoding.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/, "\\\\\\1") | ||
|
||
bad_encoding = "\u0412".force_encoding("ASCII-8BIT") | ||
expect(Heroku::JSPlugin.shellescape(bad_encoding)).to eq(expected_bad_encoding) | ||
end | ||
end | ||
|
||
context "shelljoin" do | ||
it "escapes bad shell commands" do | ||
expect(Heroku::JSPlugin.shelljoin(["`$()|;", "&><'\""])).to eq("\\`\\$\\(\\)\\|\\; \\&\\>\\<\\'\\\"") | ||
end | ||
end | ||
end | ||
end |