Commit 5a901cdf authored by Nick Thomas's avatar Nick Thomas

Strip trailing forward slashes from elasticsearch URLs

parent d5b883e1
......@@ -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