Skip to content

Commit 15515ac

Browse files
authored
Merge pull request #242 from swistak35/master
Add support for special characters in password when using url keyword
2 parents b8217c4 + 7193504 commit 15515ac

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/influxdb/config.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ def opts_from_url(url)
146146

147147
def opts_from_non_params(url)
148148
{}.tap do |o|
149-
o[:host] = url.host if url.host
150-
o[:port] = url.port if url.port
151-
o[:username] = url.user if url.user
152-
o[:password] = url.password if url.password
153-
o[:database] = url.path[1..-1] if url.path.length > 1
149+
o[:host] = url.host if url.host
150+
o[:port] = url.port if url.port
151+
o[:username] = URI.decode_www_form_component(url.user) if url.user
152+
o[:password] = URI.decode_www_form_component(url.password) if url.password
153+
o[:database] = url.path[1..-1] if url.path.length > 1
154154
o[:use_ssl] = url.scheme == "https".freeze
155155

156156
o[:udp] = { host: o[:host], port: o[:port] } if url.scheme == "udp"

spec/influxdb/config_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@
162162
expect(conf).not_to be_async
163163
end
164164

165+
context "with encoded values" do
166+
let(:url) { "https://weird%24user:weird%25pass@influx.example.com:8765/testdb" }
167+
168+
it "decode encoded values" do
169+
expect(conf.username).to eq "weird$user"
170+
expect(conf.password).to eq "weird%pass"
171+
end
172+
end
173+
165174
context "UDP" do
166175
let(:url) { "udp://test.localhost:2345?discard_write_errors=1" }
167176
specify { expect(conf).to be_udp }

0 commit comments

Comments
 (0)