From 92ddd474a72b30683f1a073476a2633e430601d8 Mon Sep 17 00:00:00 2001 From: Augustin Gottlieb <33221555+aguspe@users.noreply.github.com> Date: Sun, 24 May 2026 18:56:18 +0200 Subject: [PATCH 1/2] [rb] trim whitespace around NO_PROXY entries --- rb/lib/selenium/webdriver/common/proxy.rb | 2 +- rb/lib/selenium/webdriver/remote/http/default.rb | 2 +- .../selenium/webdriver/remote/capabilities_spec.rb | 12 ++++++++++++ .../selenium/webdriver/remote/http/default_spec.rb | 14 ++++++++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/rb/lib/selenium/webdriver/common/proxy.rb b/rb/lib/selenium/webdriver/common/proxy.rb index 644511575915e..4c804338f15e4 100644 --- a/rb/lib/selenium/webdriver/common/proxy.rb +++ b/rb/lib/selenium/webdriver/common/proxy.rb @@ -145,7 +145,7 @@ def as_json(*) 'proxyType' => TYPES[type].downcase, 'ftpProxy' => ftp, 'httpProxy' => http, - 'noProxy' => no_proxy.is_a?(String) ? no_proxy.split(', ') : no_proxy, + 'noProxy' => no_proxy.is_a?(String) ? no_proxy.split(',').map(&:strip).reject(&:empty?) : no_proxy, 'proxyAutoconfigUrl' => pac, 'sslProxy' => ssl, 'autodetect' => auto_detect, diff --git a/rb/lib/selenium/webdriver/remote/http/default.rb b/rb/lib/selenium/webdriver/remote/http/default.rb index 2677eefc2de15..15e35c8b15f61 100644 --- a/rb/lib/selenium/webdriver/remote/http/default.rb +++ b/rb/lib/selenium/webdriver/remote/http/default.rb @@ -150,7 +150,7 @@ def use_proxy? return false if proxy.nil? if proxy.no_proxy - ignored = proxy.no_proxy.split(',').any? do |host| + ignored = proxy.no_proxy.split(',').map(&:strip).reject(&:empty?).any? do |host| host == '*' || host == server_url.host || ( begin diff --git a/rb/spec/unit/selenium/webdriver/remote/capabilities_spec.rb b/rb/spec/unit/selenium/webdriver/remote/capabilities_spec.rb index b53bb44c060f4..a0329e243b2a8 100644 --- a/rb/spec/unit/selenium/webdriver/remote/capabilities_spec.rb +++ b/rb/spec/unit/selenium/webdriver/remote/capabilities_spec.rb @@ -29,6 +29,18 @@ module Remote expect(caps.as_json['proxy']['noProxy']).to eq(%w[proxy_url localhost]) end + it 'converts noProxy from comma-only separated string to array' do + proxy = Proxy.new(no_proxy: 'proxy_url,localhost') + caps = described_class.new(proxy: proxy) + expect(caps.as_json['proxy']['noProxy']).to eq(%w[proxy_url localhost]) + end + + it 'trims whitespace around noProxy entries' do + proxy = Proxy.new(no_proxy: ' proxy_url , localhost ') + caps = described_class.new(proxy: proxy) + expect(caps.as_json['proxy']['noProxy']).to eq(%w[proxy_url localhost]) + end + it 'does not convert noProxy if it is already array' do proxy = Proxy.new(no_proxy: ['proxy_url']) caps = described_class.new(proxy: proxy) diff --git a/rb/spec/unit/selenium/webdriver/remote/http/default_spec.rb b/rb/spec/unit/selenium/webdriver/remote/http/default_spec.rb index 21eff54011c37..07bf9c2404d99 100644 --- a/rb/spec/unit/selenium/webdriver/remote/http/default_spec.rb +++ b/rb/spec/unit/selenium/webdriver/remote/http/default_spec.rb @@ -123,6 +123,20 @@ module Http expect(http).not_to be_proxy end end + + it "trims whitespace around entries in #{no_proxy_var}" do + with_env('http_proxy' => 'proxy.org:8080', no_proxy_var => 'localhost, example.com') do + http = client.send :http + expect(http).not_to be_proxy + end + end + + it "trims leading whitespace on a single entry in #{no_proxy_var}" do + with_env('http_proxy' => 'proxy.org:8080', no_proxy_var => ' example.com') do + http = client.send :http + expect(http).not_to be_proxy + end + end end it 'raises a sane error if a proxy is refusing connections' do From ec1c324ecb49ddcbc4741f06e39a7a89210e8c35 Mon Sep 17 00:00:00 2001 From: Augustin Gottlieb <33221555+aguspe@users.noreply.github.com> Date: Sun, 24 May 2026 20:57:39 +0200 Subject: [PATCH 2/2] fix lint --- .../selenium/webdriver/remote/http/default.rb | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/rb/lib/selenium/webdriver/remote/http/default.rb b/rb/lib/selenium/webdriver/remote/http/default.rb index 15e35c8b15f61..62bd975deca39 100644 --- a/rb/lib/selenium/webdriver/remote/http/default.rb +++ b/rb/lib/selenium/webdriver/remote/http/default.rb @@ -148,24 +148,22 @@ def proxy def use_proxy? return false if proxy.nil? + return true unless proxy.no_proxy - if proxy.no_proxy - ignored = proxy.no_proxy.split(',').map(&:strip).reject(&:empty?).any? do |host| - host == '*' || - host == server_url.host || ( - begin - IPAddr.new(host).include?(server_url.host) - rescue ArgumentError - false - end - ) - end + !proxy_ignored? + end - !ignored - else - true + def proxy_ignored? + proxy.no_proxy.split(',').map(&:strip).reject(&:empty?).any? do |host| + host == '*' || host == server_url.host || ip_match?(host) end end + + def ip_match?(host) + IPAddr.new(host).include?(server_url.host) + rescue ArgumentError + false + end end # Default end # Http end # Remote