@@ -60,6 +60,20 @@ defmodule Plug.Router.UtilsTest do
6060 build_path_match ( "foo/bar:username" )
6161 end
6262
63+ test "build match with escaped identifiers" do
64+ assert quote ( @ opts , do: { [ ] , [ "foo" , ":" ] } ) == build_path_match ( "foo/\\ :" )
65+ assert quote ( @ opts , do: { [ ] , [ "foo" , ":id" ] } ) == build_path_match ( "/foo/\\ :id" )
66+ assert quote ( @ opts , do: { [ ] , [ "foo" , ":username" ] } ) == build_path_match ( "foo/\\ :username" )
67+
68+ assert quote ( @ opts , do: { [ :id , :post_id ] , [ "foo" , id , ":name" , post_id ] } ) ==
69+ build_path_match ( "/foo/:id/\\ :name/:post_id" )
70+
71+ assert quote ( @ opts , do: { [ ] , [ "foo" , "bar-:id" ] } ) == build_path_match ( "/foo/bar-\\ :id" )
72+
73+ assert quote ( @ opts , do: { [ ] , [ "foo" , "bar:batchDelete" ] } ) ==
74+ build_path_match ( "foo/bar\\ :batchDelete" )
75+ end
76+
6377 test "build match only with glob" do
6478 assert quote ( @ opts , do: { [ :bar ] , bar } ) == build_path_match ( "*bar" )
6579 assert quote ( @ opts , do: { [ :glob ] , glob } ) == build_path_match ( "/*glob" )
@@ -70,6 +84,14 @@ defmodule Plug.Router.UtilsTest do
7084 assert quote ( @ opts , do: { [ :glob ] , [ "foo" | glob ] } ) == build_path_match ( "foo/*glob" )
7185 end
7286
87+ test "build match with escaped glob" do
88+ assert quote ( @ opts , do: { [ ] , [ "*bar" ] } ) == build_path_match ( "\\ *bar" )
89+ assert quote ( @ opts , do: { [ ] , [ "*glob" ] } ) == build_path_match ( "/\\ *glob" )
90+
91+ assert quote ( @ opts , do: { [ ] , [ "foo" , "*bar" ] } ) == build_path_match ( "/foo/\\ *bar" )
92+ assert quote ( @ opts , do: { [ ] , [ "foo" , "*glob" ] } ) == build_path_match ( "foo/\\ *glob" )
93+ end
94+
7395 test "build invalid match with empty matches" do
7496 assert_raise Plug.Router.InvalidSpecError ,
7597 "invalid dynamic path. The characters : and * must be immediately followed by lowercase letters or underscore, got: :" ,
0 commit comments