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
read_attribute(:elasticsearch_url).split(',').map(&:strip)
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
{
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
expect(setting.elasticsearch_url).to eq(%w[http://example.com https://invalid.invalid:9200])
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
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