Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/rack_reverse_proxy/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -115,7 +115,7 @@ def with_substitutions?
end

def substitute_matches
URI(matches.substitute(url))
Addressable::URI.parse(matches.substitute(url))
end
end

Expand Down
39 changes: 39 additions & 0 deletions spec/rack_reverse_proxy/rule_spec.rb
Original file line number Diff line number Diff line change
@@ -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