Skip to content

Commit

Permalink
Avoid failing even if given path does not match with prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
namusyaka committed Dec 30, 2016
1 parent 8157b96 commit 6a24f65
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#### Fixes

* [#1548](https://github.com/ruby-grape/grape/pull/1548): Avoid failing even if given path does not match with prefix - [@thomas-peyric](https://github.com/thomas-peyric), [@namusyaka](https://github.com/namusyaka).
* Your contribution here.

### 0.19.0 (12/18/2016)
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/middleware/versioner/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def default_options
def before
path = env[Grape::Http::Headers::PATH_INFO].dup

if prefix && path.index(prefix).zero?
if prefix && path.index(prefix) == 0
path.sub!(prefix, '')
path = Grape::Router.normalize_path(path)
end
Expand Down
7 changes: 7 additions & 0 deletions spec/grape/middleware/versioner/path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,11 @@
end
end
end

context 'with prefix, but requested version is not matched' do
let(:options) { { prefix: '/v1', pattern: /v./i } }
it 'recognizes potential version' do
expect(subject.call('PATH_INFO' => '/v3/foo').last).to eq('v3')
end
end
end

0 comments on commit 6a24f65

Please sign in to comment.