File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -158,7 +158,12 @@ def parse_header_params(params)
158
158
def parse_path ( path , version )
159
159
# adapt format to swagger format
160
160
parsed_path = path . gsub ( '(.:format)' , '.{format}' )
161
- parsed_path = parsed_path . gsub ( /:([a-z]+)/ , '{\1}' )
161
+ # This is attempting to emulate the behavior of
162
+ # Rack::Mount::Strexp. We cannot use Strexp directly because
163
+ # all it does is generate regular expressions for parsing URLs.
164
+ # TODO: Implement a Racc tokenizer to properly generate the
165
+ # parsed path.
166
+ parsed_path = parsed_path . gsub ( /:([a-zA-Z_]\w *)/ , '{\1}' )
162
167
# add the version
163
168
parsed_path = parsed_path . gsub ( '{version}' , version ) if version
164
169
parsed_path
Original file line number Diff line number Diff line change @@ -51,6 +51,24 @@ class HelperTestAPI < Grape::API
51
51
@api . parse_path ( path , nil ) . should == "{abc}/def.{format}"
52
52
end
53
53
54
+ it "should parse a path that has vars with underscores in the name" do
55
+ path = "abc/:def_g(.:format)"
56
+ @api . parse_path ( path , nil ) . should == "abc/{def_g}.{format}"
57
+
58
+ end
59
+
60
+ it "should parse a path that has vars with numbers in the name" do
61
+ path = "abc/:sha1(.:format)"
62
+ @api . parse_path ( path , nil ) . should == "abc/{sha1}.{format}"
63
+ end
64
+
65
+ it "should parse a path that has multiple variables" do
66
+ path1 = "abc/:def/:geh(.:format)"
67
+ path2 = "abc/:def:geh(.:format)"
68
+ @api . parse_path ( path1 , nil ) . should == "abc/{def}/{geh}.{format}"
69
+ @api . parse_path ( path2 , nil ) . should == "abc/{def}{geh}.{format}"
70
+ end
71
+
54
72
it "should parse the path with a specified version" do
55
73
path = ":abc/{version}/def(.:format)"
56
74
@api . parse_path ( path , 'v1' ) . should == "{abc}/v1/def.{format}"
You can’t perform that action at this time.
0 commit comments