From 0ec47813f10672ab9ef8ce9c2ad5fba0df67634c Mon Sep 17 00:00:00 2001 From: Stefan Sundin Date: Thu, 5 Apr 2018 14:48:35 -0700 Subject: [PATCH 1/3] Prevent .curlrc from being loaded. --- Library/Homebrew/cmd/vendor-install.sh | 1 + Library/Homebrew/test/utils/curl_spec.rb | 10 ++++++++++ Library/Homebrew/utils/curl.rb | 1 + 3 files changed, 12 insertions(+) create mode 100644 Library/Homebrew/test/utils/curl_spec.rb diff --git a/Library/Homebrew/cmd/vendor-install.sh b/Library/Homebrew/cmd/vendor-install.sh index 8aba2174e5bad..a97b816c05c9d 100644 --- a/Library/Homebrew/cmd/vendor-install.sh +++ b/Library/Homebrew/cmd/vendor-install.sh @@ -48,6 +48,7 @@ fetch() { local temporary_path curl_args=( + -q # do not load .curlrc (must be the first argument) --fail --remote-time --location diff --git a/Library/Homebrew/test/utils/curl_spec.rb b/Library/Homebrew/test/utils/curl_spec.rb new file mode 100644 index 0000000000000..65ad173ab95a0 --- /dev/null +++ b/Library/Homebrew/test/utils/curl_spec.rb @@ -0,0 +1,10 @@ +require "utils/curl" + +describe "curl" do + describe "curl_args" do + it "returns -q as the first argument" do + # -q must be the first argument according to "man curl" + expect(curl_args("foo")[1]).to eq("-q") + end + end +end diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 7b2488ec72dbb..4770dc03b7d76 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -14,6 +14,7 @@ def curl_executable def curl_args(*extra_args, show_output: false, user_agent: :default) args = [ curl_executable.to_s, + "-q", # do not load .curlrc (must be the first argument) "--show-error", ] From 0bd58693199c42e2cadfbb428d8ab9be9a27ebfe Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sun, 8 Apr 2018 15:51:58 -0700 Subject: [PATCH 2/3] Add/use HOMEBREW_CURLRC variable. --- Library/Homebrew/cmd/vendor-install.sh | 11 +++++++++-- Library/Homebrew/manpages/brew.1.md.erb | 4 ++++ Library/Homebrew/utils/curl.rb | 13 ++++++++----- docs/Manpage.md | 4 ++++ manpages/brew-cask.1 | 2 +- manpages/brew.1 | 6 +++++- 6 files changed, 31 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/cmd/vendor-install.sh b/Library/Homebrew/cmd/vendor-install.sh index a97b816c05c9d..5a734a2db4bb4 100644 --- a/Library/Homebrew/cmd/vendor-install.sh +++ b/Library/Homebrew/cmd/vendor-install.sh @@ -47,8 +47,15 @@ fetch() { local sha local temporary_path - curl_args=( - -q # do not load .curlrc (must be the first argument) + curl_args=() + + # do not load .curlrc unless requested (must be the first argument) + if [[ -n "$HOMEBREW_CURLRC" ]] + then + curl_args[${#curl_args[*]}]="-q" + fi + + curl_args+=( --fail --remote-time --location diff --git a/Library/Homebrew/manpages/brew.1.md.erb b/Library/Homebrew/manpages/brew.1.md.erb index a4854cc67c5be..638117044ee46 100644 --- a/Library/Homebrew/manpages/brew.1.md.erb +++ b/Library/Homebrew/manpages/brew.1.md.erb @@ -136,6 +136,10 @@ can take several different forms: *Default:* `~/Library/Caches/Homebrew`. + * `HOMEBREW_CURLRC`: + If set, Homebrew will not pass `-q` when invoking `curl`(1) (which disables + the use of `curlrc`). + * `HOMEBREW_CURL_VERBOSE`: If set, Homebrew will pass `--verbose` when invoking `curl`(1). diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 4770dc03b7d76..5e2c1c98d857f 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -12,11 +12,14 @@ def curl_executable end def curl_args(*extra_args, show_output: false, user_agent: :default) - args = [ - curl_executable.to_s, - "-q", # do not load .curlrc (must be the first argument) - "--show-error", - ] + args = [curl_executable.to_s] + + # do not load .curlrc unless requested (must be the first argument) + if ENV["HOMEBREW_CURLRC"] + args << "-q" + end + + args << "--show-error" args << "--user-agent" << case user_agent when :browser, :fake diff --git a/docs/Manpage.md b/docs/Manpage.md index 8d0408d7ba2df..e75fdcda9a9de 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -1110,6 +1110,10 @@ can take several different forms: *Default:* `~/Library/Caches/Homebrew`. + * `HOMEBREW_CURLRC`: + If set, Homebrew will not pass `-q` when invoking `curl`(1) (which disables + the use of `curlrc`). + * `HOMEBREW_CURL_VERBOSE`: If set, Homebrew will pass `--verbose` when invoking `curl`(1). diff --git a/manpages/brew-cask.1 b/manpages/brew-cask.1 index 6b32a90518676..346c45d6a81e8 100644 --- a/manpages/brew-cask.1 +++ b/manpages/brew-cask.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BREW\-CASK" "1" "March 2018" "Homebrew" "brew-cask" +.TH "BREW\-CASK" "1" "April 2018" "Homebrew" "brew-cask" . .SH "NAME" \fBbrew\-cask\fR \- a friendly binary installer for macOS diff --git a/manpages/brew.1 b/manpages/brew.1 index 163b2e4560485..69f0b31ab76a3 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BREW" "1" "March 2018" "Homebrew" "brew" +.TH "BREW" "1" "April 2018" "Homebrew" "brew" . .SH "NAME" \fBbrew\fR \- The missing package manager for macOS @@ -1128,6 +1128,10 @@ If set, instructs Homebrew to use the given directory as the download cache\. \fIDefault:\fR \fB~/Library/Caches/Homebrew\fR\. . .TP +\fBHOMEBREW_CURLRC\fR +If set, Homebrew will not pass \fB\-q\fR when invoking \fBcurl\fR(1) (which disables the use of \fBcurlrc\fR)\. +. +.TP \fBHOMEBREW_CURL_VERBOSE\fR If set, Homebrew will pass \fB\-\-verbose\fR when invoking \fBcurl\fR(1)\. . From d331c47de074b416b2e9d5ec340f7af71cc6a6d9 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sun, 8 Apr 2018 16:07:21 -0700 Subject: [PATCH 3/3] diagnostic: remove check_user_curlrc check. --- Library/Homebrew/diagnostic.rb | 15 --------------- Library/Homebrew/test/diagnostic_spec.rb | 9 --------- Library/Homebrew/test/utils/curl_spec.rb | 7 ++++++- 3 files changed, 6 insertions(+), 25 deletions(-) diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 18808033f5e13..736f35ff19786 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -480,21 +480,6 @@ def check_user_path_3 EOS end - def check_user_curlrc - curlrc_found = %w[CURL_HOME HOME].any? do |var| - ENV[var] && File.exist?("#{ENV[var]}/.curlrc") - end - return unless curlrc_found - - <<~EOS - You have a curlrc file - If you have trouble downloading packages with Homebrew, then maybe this - is the problem? If the following command doesn't work, then try removing - your curlrc: - curl #{Formatter.url("https://github.com")} - EOS - end - def check_for_gettext find_relative_paths("lib/libgettextlib.dylib", "lib/libintl.dylib", diff --git a/Library/Homebrew/test/diagnostic_spec.rb b/Library/Homebrew/test/diagnostic_spec.rb index 8f82e71b1fb17..52e7d3a392ed9 100644 --- a/Library/Homebrew/test/diagnostic_spec.rb +++ b/Library/Homebrew/test/diagnostic_spec.rb @@ -131,15 +131,6 @@ end end - specify "#check_user_curlrc" do - mktmpdir do |path| - FileUtils.touch "#{path}/.curlrc" - ENV["CURL_HOME"] = path - - expect(subject.check_user_curlrc).to match("You have a curlrc file") - end - end - specify "#check_for_config_scripts" do mktmpdir do |path| file = "#{path}/foo-config" diff --git a/Library/Homebrew/test/utils/curl_spec.rb b/Library/Homebrew/test/utils/curl_spec.rb index 65ad173ab95a0..7e3cc18f7a3f8 100644 --- a/Library/Homebrew/test/utils/curl_spec.rb +++ b/Library/Homebrew/test/utils/curl_spec.rb @@ -2,9 +2,14 @@ describe "curl" do describe "curl_args" do - it "returns -q as the first argument" do + it "returns -q as the first argument when HOMEBREW_CURLRC is set" do + ENV["HOMEBREW_CURLRC"] = "1" # -q must be the first argument according to "man curl" expect(curl_args("foo")[1]).to eq("-q") end + + it "doesn't return -q as the first argument when HOMEBREW_CURLRC is not set" do + expect(curl_args("foo")[1]).to_not eq("-q") + end end end