Skip to content

Commit

Permalink
Merge pull request #1865 from native-api/quote_varvalues
Browse files Browse the repository at this point in the history
Double-quote variable values for `set` and `export` commands
  • Loading branch information
BanzaiMan committed Mar 9, 2020
2 parents c708e1c + 0c44f40 commit 4a41f03
Show file tree
Hide file tree
Showing 30 changed files with 43 additions and 36 deletions.
4 changes: 2 additions & 2 deletions lib/travis/build/addons/sonarcloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def install_sonar_scanner
sh.raw(scr, echo: false)
sh.mv "#{SCANNER_HOME}/sonar-scanner-*", "#{SCANNER_HOME}/sonar-scanner"
sh.export 'SONAR_SCANNER_HOME', "#{SCANNER_HOME}/sonar-scanner", echo: true
sh.export 'PATH', %{"$PATH:#{SCANNER_HOME}/sonar-scanner/bin"}, echo: false
sh.export 'PATH', "$PATH:#{SCANNER_HOME}/sonar-scanner/bin", echo: false
end

def install_build_wrapper
Expand Down Expand Up @@ -106,7 +106,7 @@ def install_build_wrapper
sh.cmd "unzip -o $sq_build_wrapper_dir/#{build_wrapper}.zip -d $sq_build_wrapper_dir", echo: false
end

sh.export 'PATH', "\"$PATH:$sq_build_wrapper_dir/#{build_wrapper}\"", echo: false
sh.export 'PATH', "$PATH:$sq_build_wrapper_dir/#{build_wrapper}", echo: false
end

def run
Expand Down
2 changes: 1 addition & 1 deletion lib/travis/shell/generator/bash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def handle_newline(options = {})

def handle_export(data, options = {})
key, value, options = handle_secure_vars(*data, options)
handle_cmd("export #{key}=#{value}", options)
handle_cmd("export #{key}=#{doublequote(value)}", options)
end
alias handle_set handle_export

Expand Down
7 changes: 7 additions & 0 deletions lib/travis/shell/generator/bash/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ def ansi(string, keys)
def escape(code)
Shellwords.escape(Coder.force_encoding(code.to_s))
end

# Format as a single argument but allow shell syntax inside
def doublequote(code)
# since Bash syntax is permitted, it's caller's duty to
# escape any doublequotes inside if necessary
'"' + Coder.force_encoding(code.to_s) + '"'
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/build/addons/code_climate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
let(:export_repo_token) { [:export, ['CODECLIMATE_REPO_TOKEN', '1234']] }

it_behaves_like 'compiled script' do
let(:code) { ['CODECLIMATE_REPO_TOKEN=1234'] }
let(:code) { ['CODECLIMATE_REPO_TOKEN="1234"'] }
end

describe 'with a token' do
Expand Down
2 changes: 1 addition & 1 deletion spec/build/addons/coverity_scan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
before { addon.script }

# it_behaves_like 'compiled script' do
# let(:code) { ['CODECLIMATE_REPO_TOKEN=1234'] }
# let(:code) { ['CODECLIMATE_REPO_TOKEN="1234"'] }
# end

xit 'needs specs!'
Expand Down
2 changes: 1 addition & 1 deletion spec/build/addons/sauce_connect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
end

it_behaves_like 'compiled script' do
let(:code) { ['sauce_connect', 'TRAVIS_SAUCE_CONNECT=true'] }
let(:code) { ['sauce_connect', 'TRAVIS_SAUCE_CONNECT="true"'] }
end

shared_examples_for 'starts sauce connect' do
Expand Down
12 changes: 6 additions & 6 deletions spec/build/addons/sonarcloud_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@

describe 'scanner and build wrapper installation' do
it { should include_sexp [:export, ['SONAR_SCANNER_HOME', '${TRAVIS_HOME}/.sonarscanner/sonar-scanner'], {:echo=>true}] }
it { should include_sexp [:export, ['PATH', "\"$PATH:${TRAVIS_HOME}/.sonarscanner/sonar-scanner/bin\""]] }
it { should include_sexp [:export, ['PATH', "$PATH:${TRAVIS_HOME}/.sonarscanner/sonar-scanner/bin"]] }
it { should include_sexp [:mkdir, "$sq_build_wrapper_dir", {:recursive=>true}] }
it { should include_sexp [:export, ['PATH', "\"$PATH:$sq_build_wrapper_dir/build-wrapper-linux-x86\""]] }
it { should include_sexp [:export, ['PATH', "$PATH:$sq_build_wrapper_dir/build-wrapper-linux-x86"]] }
end

describe 'skip build wrapper installation with java' do
let(:data) { super().merge(config: { :language => 'java' })}

it { should include_sexp [:export, ['SONAR_SCANNER_HOME', '${TRAVIS_HOME}/.sonarscanner/sonar-scanner'], {:echo=>true}] }
it { should include_sexp [:export, ['PATH', "\"$PATH:${TRAVIS_HOME}/.sonarscanner/sonar-scanner/bin\""]] }
it { should include_sexp [:export, ['PATH', "$PATH:${TRAVIS_HOME}/.sonarscanner/sonar-scanner/bin"]] }
it { should_not include_sexp [:mkdir, "$sq_build_wrapper_dir", {:recursive=>true}] }
it { should_not include_sexp [:export, ['PATH', "\"$PATH:$sq_build_wrapper_dir/build-wrapper-linux-x86\""]] }
it { should_not include_sexp [:export, ['PATH', "$PATH:$sq_build_wrapper_dir/build-wrapper-linux-x86"]] }
end

describe 'skip build wrapper with invalid OS' do
let(:data) { super().merge(config: { :language => 'unkown' })}

it { should include_sexp [:export, ['SONAR_SCANNER_HOME', '${TRAVIS_HOME}/.sonarscanner/sonar-scanner'], {:echo=>true}] }
it { should include_sexp [:export, ['PATH', "\"$PATH:${TRAVIS_HOME}/.sonarscanner/sonar-scanner/bin\""]] }
it { should include_sexp [:export, ['PATH', "$PATH:${TRAVIS_HOME}/.sonarscanner/sonar-scanner/bin"]] }
it { should include_sexp [:echo, "Can't install SonarSource build wrapper for platform: $TRAVIS_OS_NAME.", {:ansi=>:red}] }
it { should_not include_sexp [:export, ['PATH', "\"$PATH:$sq_build_wrapper_dir/build-wrapper-linux-x86\""]] }
it { should_not include_sexp [:export, ['PATH', "$PATH:$sq_build_wrapper_dir/build-wrapper-linux-x86"]] }
end

describe 'new pull request analysis' do
Expand Down
2 changes: 1 addition & 1 deletion spec/build/script/android_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
it_behaves_like 'a bash script'

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=android'] }
let(:code) { ['TRAVIS_LANGUAGE="android"'] }
let(:cmds) { ['gradlew build connectedCheck'] }
end

Expand Down
2 changes: 1 addition & 1 deletion spec/build/script/c_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
it_behaves_like 'a bash script'

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=c'] }
let(:code) { ['TRAVIS_LANGUAGE="c"'] }
let(:cmds) { ['./configure && make && make test'] }
end

Expand Down
2 changes: 1 addition & 1 deletion spec/build/script/clojure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
it_behaves_like 'a bash script'

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=clojure'] }
let(:code) { ['TRAVIS_LANGUAGE="clojure"'] }
let(:cmds) { ['lein test'] }
end

Expand Down
2 changes: 1 addition & 1 deletion spec/build/script/cpp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
it_behaves_like 'a bash script'

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=cpp'] }
let(:code) { ['TRAVIS_LANGUAGE="cpp"'] }
let(:cmds) { ['make test'] }
end

Expand Down
2 changes: 1 addition & 1 deletion spec/build/script/csharp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
it_behaves_like 'a bash script'

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=csharp'] }
let(:code) { ['TRAVIS_LANGUAGE="csharp"'] }
end

it_behaves_like 'a build script sexp'
Expand Down
2 changes: 1 addition & 1 deletion spec/build/script/elixir_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
it_behaves_like 'a bash script'

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=elixir'] }
let(:code) { ['TRAVIS_LANGUAGE="elixir"'] }
end

it_behaves_like 'a build script sexp'
Expand Down
2 changes: 1 addition & 1 deletion spec/build/script/elm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
it { store_example }

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=elm'] }
let(:code) { ['TRAVIS_LANGUAGE="elm"'] }
let(:cmds) { ['elm-test'] }
end

Expand Down
2 changes: 1 addition & 1 deletion spec/build/script/erlang_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
it_behaves_like 'a bash script'

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=erlang'] }
let(:code) { ['TRAVIS_LANGUAGE="erlang"'] }
let(:cmds) { ['rebar skip_deps=true eunit'] }
end

Expand Down
2 changes: 1 addition & 1 deletion spec/build/script/go_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
it_behaves_like 'a bash script'

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=go'] }
let(:code) { ['TRAVIS_LANGUAGE="go"'] }
let(:code) { ['go test'] }
end

Expand Down
2 changes: 1 addition & 1 deletion spec/build/script/groovy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
it_behaves_like 'a bash script'

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=groovy'] }
let(:code) { ['TRAVIS_LANGUAGE="groovy"'] }
let(:cmds) { ['gradlew check'] }
end

Expand Down
2 changes: 1 addition & 1 deletion spec/build/script/haskell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
it_behaves_like 'a bash script'

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=haskell'] }
let(:code) { ['TRAVIS_LANGUAGE="haskell"'] }
let(:cmds) { ['cabal test'] }
end

Expand Down
2 changes: 1 addition & 1 deletion spec/build/script/node_js_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
it_behaves_like 'a bash script'

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=node_js'] }
let(:code) { ['TRAVIS_LANGUAGE="node_js"'] }
let(:cmds) { ['npm test'] }
end

Expand Down
2 changes: 1 addition & 1 deletion spec/build/script/objective_c_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
it_behaves_like 'a bash script'

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=objective_c'] }
let(:code) { ['TRAVIS_LANGUAGE="objective_c"'] }
let(:cmds) { ['bundle exec rake spec'] }
end

Expand Down
2 changes: 1 addition & 1 deletion spec/build/script/perl6_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
it_behaves_like 'a bash script'

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=perl6'] }
let(:code) { ['TRAVIS_LANGUAGE="perl6"'] }
end

it_behaves_like 'a build script sexp'
Expand Down
2 changes: 1 addition & 1 deletion spec/build/script/perl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
it_behaves_like 'a bash script'

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=perl'] }
let(:code) { ['TRAVIS_LANGUAGE="perl"'] }
let(:cmds) { ['./Build test'] }
end

Expand Down
2 changes: 1 addition & 1 deletion spec/build/script/php_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
it_behaves_like 'a bash script'

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=php'] }
let(:code) { ['TRAVIS_LANGUAGE="php"'] }
let(:cmds) { ['phpunit'] }
end

Expand Down
2 changes: 1 addition & 1 deletion spec/build/script/pure_java_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
it_behaves_like 'a bash script'

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=java'] }
let(:code) { ['TRAVIS_LANGUAGE="java"'] }
let(:cmds) { ['gradlew check'] }
end

Expand Down
2 changes: 1 addition & 1 deletion spec/build/script/python_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
it_behaves_like 'a bash script'

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=python'] }
let(:code) { ['TRAVIS_LANGUAGE="python"'] }
let(:cmds) { ['pip install'] }
end

Expand Down
2 changes: 1 addition & 1 deletion spec/build/script/ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
it_behaves_like 'a bash script'

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=ruby'] }
let(:code) { ['TRAVIS_LANGUAGE="ruby"'] }
let(:cmds) { ['bundle install', 'bundle exec rake'] }
end

Expand Down
2 changes: 1 addition & 1 deletion spec/build/script/rust_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
it_behaves_like 'a bash script'

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=rust'] }
let(:code) { ['TRAVIS_LANGUAGE="rust"'] }
let(:cmds) { ['cargo build --verbose'] }
end

Expand Down
2 changes: 1 addition & 1 deletion spec/build/script/scala_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
it_behaves_like 'a bash script'

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=scala'] }
let(:code) { ['TRAVIS_LANGUAGE="scala"'] }
let(:cmds) { ['sbt ++2.12.8 test'] }
end

Expand Down
2 changes: 1 addition & 1 deletion spec/build/script/smalltalk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
it_behaves_like 'a bash script'

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=smalltalk'] }
let(:code) { ['TRAVIS_LANGUAGE="smalltalk"'] }
let(:cmds) { ['smalltalkci'] }
end

Expand Down
4 changes: 2 additions & 2 deletions spec/shell/generator/bash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@
describe :export do
it 'generates an export command' do
@sexp = [:export, ['FOO', 'foo'], echo: true]
expect(code).to eql("travis_cmd export\\ FOO\\=foo --echo")
expect(code).to eql("travis_cmd export\\ FOO\\=\\\"foo\\\" --echo")
end

it 'adds --display FOO=[secure] if the given value is tainted' do
@sexp = [:export, ['FOO', 'foo'], echo: true, secure: true]
expect(code).to eql("travis_cmd export\\ FOO\\=foo --echo --display export\\ FOO\\=\\[secure\\] --secure")
expect(code).to eql("travis_cmd export\\ FOO\\=\\\"foo\\\" --echo --display export\\ FOO\\=\\[secure\\] --secure")
end
end

Expand Down

0 comments on commit 4a41f03

Please sign in to comment.