@@ -39,8 +39,22 @@ pub fn get_cwd() -> PyResult<String> {
3939pub fn convert_to_route_path ( path : & str ) -> String {
4040 let mut result = path. replace ( "\\ " , "/" ) ;
4141
42- if result. starts_with ( "routes/" ) {
43- result = result[ 7 ..] . to_string ( ) ;
42+ if result. starts_with ( "./" ) {
43+ result = result[ 2 ..] . to_string ( ) ;
44+ }
45+ if result. starts_with ( ".\\ " ) {
46+ result = result[ 2 ..] . to_string ( ) ;
47+ }
48+
49+ if result. starts_with ( "/" ) {
50+ result = result[ 1 ..] . to_string ( ) ;
51+ }
52+
53+ if result. starts_with ( "\\ " ) {
54+ result = result[ 1 ..] . to_string ( ) ;
55+ }
56+ if result. starts_with ( "routes" ) {
57+ result = result[ 6 ..] . to_string ( ) ;
4458 }
4559
4660 while let Some ( start) = result. find ( "/(" ) {
@@ -79,6 +93,10 @@ mod tests {
7993 #[ test]
8094 fn test_convert_to_route_path ( ) {
8195 assert_eq ! ( convert_to_route_path( "routes/crud.py" ) , "/crud" ) ;
96+ assert_eq ! ( convert_to_route_path( "/routes/a/crud.py" ) , "/a/crud" ) ;
97+ assert_eq ! ( convert_to_route_path( "\\ routes/a/crud.py" ) , "/a/crud" ) ;
98+ assert_eq ! ( convert_to_route_path( "./routes/a/crud.py" ) , "/a/crud" ) ;
99+ assert_eq ! ( convert_to_route_path( ".\\ routes/a/crud.py" ) , "/a/crud" ) ;
82100 assert_eq ! ( convert_to_route_path( "routes\\ crud.py" ) , "/crud" ) ;
83101 assert_eq ! ( convert_to_route_path( "routes/a/b/c/crud.py" ) , "/a/b/c/crud" ) ;
84102 assert_eq ! (
@@ -89,6 +107,14 @@ mod tests {
89107 assert_eq ! ( convert_to_route_path( "routes/a/(b)/(c)/crud.py" ) , "/a/crud" ) ;
90108
91109 assert_eq ! ( convert_to_route_path( "routes/a/(b)/(c)/__init__.py" ) , "/a" ) ;
110+ assert_eq ! (
111+ convert_to_route_path( "routes/(singleton)/global_info.py" ) ,
112+ "/global-info"
113+ ) ;
114+ assert_eq ! (
115+ convert_to_route_path( "routes\\ (singleton)\\ global_info.py" ) ,
116+ "/global-info"
117+ ) ;
92118
93119 assert_eq ! ( convert_to_route_path( "routes/__init__.py" ) , "/" ) ;
94120
0 commit comments