Commit 871454de authored by Robert Speicher's avatar Robert Speicher

Merge branch '2039-fix-elasticsearch-url-with-path' into 'master'

Strip trailing forward slashes from elasticsearch URLs

Closes #2039

See merge request !1566
parents 2a26b12c 5a901cdf
...@@ -301,6 +301,12 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -301,6 +301,12 @@ class ApplicationSetting < ActiveRecord::Base
read_attribute(:elasticsearch_url).split(',').map(&:strip) read_attribute(:elasticsearch_url).split(',').map(&:strip)
end end
def elasticsearch_url=(values)
cleaned = values.split(',').map {|url| url.strip.gsub(%r{/*\z}, '') }
write_attribute(:elasticsearch_url, cleaned.join(','))
end
def elasticsearch_config def elasticsearch_config
{ {
url: elasticsearch_url, url: elasticsearch_url,
......
---
title: Fix Elasticsearch not working when URL ends with a forward slash
merge_request: 1566
author:
...@@ -299,6 +299,12 @@ describe ApplicationSetting, models: true do ...@@ -299,6 +299,12 @@ describe ApplicationSetting, models: true do
expect(setting.elasticsearch_url).to eq(%w[http://example.com https://invalid.invalid:9200]) expect(setting.elasticsearch_url).to eq(%w[http://example.com https://invalid.invalid:9200])
end end
it 'strips trailing slashes from URLs' do
setting.elasticsearch_url = 'http://example.com/, https://example.com:9200/, https://example.com:9200/prefix//'
expect(setting.elasticsearch_url).to eq(%w[http://example.com https://example.com:9200 https://example.com:9200/prefix])
end
end end
describe '#elasticsearch_config' do describe '#elasticsearch_config' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment