Skip to content

Commit e81f032

Browse files
committed
Fixes #809: supports UTF8 route names.
1 parent 5d15589 commit e81f032

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

.rubocop.yml

+3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ Naming:
7373
Style/AccessorGrouping:
7474
Enabled: true
7575

76+
Style/AsciiComments:
77+
Enabled: false
78+
7679
Style/ArrayCoercion:
7780
Enabled: true
7881

lib/grape-swagger.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ def combine_routes(app, doc_klass)
2929
route_match = route_path.split(/^.*?#{route.prefix}/).last
3030
next unless route_match
3131

32-
route_match = route_match.match('\/([\w|-]*?)[\.\/\(]') || route_match.match('\/([\w|-]*)$')
32+
# want to match emojis … ;)
33+
# route_match = route_match
34+
# .match('\/([\p{Alnum}|\p{Emoji}|\-|\_]*?)[\.\/\(]') || route_match.match('\/([\p{Alpha}|\p{Emoji}|\-|\_]*)$')
35+
route_match = route_match.match('\/([\p{Alnum}|\-|\_]*?)[\.\/\(]') || route_match.match('\/([\p{Alpha}|\-|\_]*)$')
3336
next unless route_match
3437

3538
resource = route_match.captures.first
@@ -85,7 +88,7 @@ def extract_parent_route(name)
8588
route_name = name.match(%r{^/?([^/]*).*$})[1]
8689
return route_name unless route_name.include? ':'
8790

88-
matches = name.match(/\/[a-z]+/)
91+
matches = name.match(/\/\p{Alpha}+/)
8992
matches.nil? ? route_name : matches[0].delete('/')
9093
end
9194

spec/issues/809_utf8_routes_spec.rb

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe '#605 root route documentation' do
6+
let(:app) do
7+
Class.new(Grape::API) do
8+
resource :grunnbeløp do
9+
desc 'returnerer grunnbeløp'
10+
get do
11+
{ message: 'hello world' }
12+
end
13+
end
14+
15+
resource :εσόδων do
16+
desc 'εσόδων'
17+
get do
18+
{ message: 'hello world' }
19+
end
20+
end
21+
22+
resource :数 do
23+
desc '数'
24+
get do
25+
{ message: 'hello world' }
26+
end
27+
end
28+
29+
resource :amount do
30+
desc 'returns amount'
31+
get do
32+
{ message: 'hello world' }
33+
end
34+
end
35+
36+
resource :👍 do
37+
desc 'returns 👍'
38+
get do
39+
{ message: 'hello world' }
40+
end
41+
end
42+
43+
add_swagger_documentation
44+
end
45+
end
46+
47+
subject do
48+
get '/swagger_doc'
49+
JSON.parse(last_response.body)['paths']
50+
end
51+
52+
specify do
53+
expect(subject.keys).to match_array ['/grunnbeløp', '/amount', '/εσόδων', '/数']
54+
end
55+
end

0 commit comments

Comments
 (0)