Skip to content

Commit da20e28

Browse files
authored
Merge pull request #1548 from ruby-grape/fix-1546
Avoid failing even if given path does not match with prefix
2 parents 8157b96 + f0711eb commit da20e28

File tree

6 files changed

+18
-3
lines changed

6 files changed

+18
-3
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ Style/MultilineIfModifier:
1818

1919
Style/RaiseArgs:
2020
Enabled: false
21+
22+
Lint/UnneededDisable:
23+
Enabled: false

Appraisals

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ end
1414
appraise 'rack-1.5.2' do
1515
gem 'rack', '1.5.2'
1616
end
17+
18+
appraise 'rails-edge' do
19+
gem 'arel', github: 'rails/arel'
20+
end

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)

gemfiles/rails_edge.gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
source 'https://rubygems.org'
44

5-
gem 'rails', github: 'rails/rails'
5+
gem 'arel', github: 'rails/arel'
66

77
group :development, :test do
88
gem 'bundler'
99
gem 'rake'
10-
gem 'rubocop', '~> 0.45.0'
10+
gem 'rubocop', '~> 0.45'
1111
end
1212

1313
group :development do

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 # rubocop:disable all
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)