Skip to content

Commit

Permalink
Merge 253ba0e into c59bfea
Browse files Browse the repository at this point in the history
  • Loading branch information
jgraichen committed Jul 2, 2019
2 parents c59bfea + 253ba0e commit 90d9b6d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/acfs/location.rb
Expand Up @@ -33,7 +33,7 @@ def extract_from(*args)

def str
uri = raw.dup
uri.path = URI.escape '/' + struct.map {|s| lookup_arg(s, args) }.join('/')
uri.path = '/' + struct.map {|s| lookup_arg(s, args) }.join('/')
uri.to_s
end

Expand All @@ -58,7 +58,7 @@ def lookup_arg(arg, args)

def lookup_replacement(sym, args)
value = get_replacement(sym, args).to_s
return value unless value.empty?
return ::URI.encode_www_form_component(value) unless value.empty?

raise ArgumentError.new "Cannot replace path argument `#{sym}' with empty string."
end
Expand Down
23 changes: 23 additions & 0 deletions spec/acfs/location_spec.rb
@@ -0,0 +1,23 @@
require 'spec_helper'

describe ::Acfs::Location do
let(:location) { described_class.new(uri, args) }
let(:uri) { 'http://localhost/users/:id' }
let(:args) { {id: 4} }

describe '#str' do
subject(:str) { location.str }

it 'replaces variables with values' do
expect(str).to eq 'http://localhost/users/4'
end

context 'with special characters' do
let(:args) { {id: '4 [@(\/!^$'} }

it 'escapes special characters' do
expect(str).to eq 'http://localhost/users/4+%5B%40%28%5C%2F%21%5E%24'
end
end
end
end

0 comments on commit 90d9b6d

Please sign in to comment.