Skip to content

Commit 6a24f65

Browse files
committed
Avoid failing even if given path does not match with prefix
1 parent 8157b96 commit 6a24f65

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#### Fixes
1010

11+
* [#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).
1112
* Your contribution here.
1213

1314
### 0.19.0 (12/18/2016)

lib/grape/middleware/versioner/path.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def default_options
2626
def before
2727
path = env[Grape::Http::Headers::PATH_INFO].dup
2828

29-
if prefix && path.index(prefix).zero?
29+
if prefix && path.index(prefix) == 0
3030
path.sub!(prefix, '')
3131
path = Grape::Router.normalize_path(path)
3232
end

spec/grape/middleware/versioner/path_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,11 @@
4141
end
4242
end
4343
end
44+
45+
context 'with prefix, but requested version is not matched' do
46+
let(:options) { { prefix: '/v1', pattern: /v./i } }
47+
it 'recognizes potential version' do
48+
expect(subject.call('PATH_INFO' => '/v3/foo').last).to eq('v3')
49+
end
50+
end
4451
end

0 commit comments

Comments
 (0)