diff --git a/lib/rack_reverse_proxy/rule.rb b/lib/rack_reverse_proxy/rule.rb index 0635482..4916909 100644 --- a/lib/rack_reverse_proxy/rule.rb +++ b/lib/rack_reverse_proxy/rule.rb @@ -93,11 +93,11 @@ def raw_uri end def just_uri - URI.parse(url) + Addressable::URI.parse(url) end def uri_with_path - URI.join(url, path) + Addressable::URI.join(url, path) end def evaluate(url) @@ -115,7 +115,7 @@ def with_substitutions? end def substitute_matches - URI(matches.substitute(url)) + Addressable::URI.parse(matches.substitute(url)) end end diff --git a/spec/rack_reverse_proxy/rule_spec.rb b/spec/rack_reverse_proxy/rule_spec.rb new file mode 100644 index 0000000..1e458cb --- /dev/null +++ b/spec/rack_reverse_proxy/rule_spec.rb @@ -0,0 +1,39 @@ +require "spec_helper" + +module RackReverseProxy + RSpec.describe Rule do + describe '#get_uri' do + context 'with path' do + it 'accepts URLs with square brackets' do + rule = RackReverseProxy::Rule.new('/test', 'http://example.com') + + uri = rule.get_uri('/test/[id]', {}, nil, nil) + + expect(uri.to_s).to eq 'http://example.com/test/[id]' + end + end + + context 'with substitutions' do + it 'accepts URLs with square brackets' do + rule = RackReverseProxy::Rule.new(%r{^/test/(.*)}, 'http://example.com/test/$1') + + uri = rule.get_uri('/test/[id]', {}, nil, nil) + + expect(uri.to_s).to eq 'http://example.com/test/[id]' + end + end + + context 'with custom url' do + it 'accepts URLs with square brackets' do + rule = RackReverseProxy::Rule.new(%r{^/test/(.*)}) + + expect_any_instance_of(RackReverseProxy::Rule::Matches).to receive(:custom_url).and_return('/test/[id]') + + uri = rule.get_uri('/test/[id]', {}, nil, nil) + + expect(uri.to_s).to eq '/test/[id]' + end + end + end + end +end