浏览代码

Reject all external routes when parsing a route (#1272)

* reject all external routes when parsing a route

* fix children routers
ealmloff 1 年之前
父节点
当前提交
61ce3dd6b7
共有 2 个文件被更改,包括 8 次插入2 次删除
  1. 7 1
      packages/router-macro/src/lib.rs
  2. 1 1
      packages/router-macro/src/route_tree.rs

+ 7 - 1
packages/router-macro/src/lib.rs

@@ -485,7 +485,13 @@ impl RouteEnum {
                     let mut segments = route.split('/');
                     // skip the first empty segment
                     if s.starts_with('/') {
-                        segments.next();
+                        let _ = segments.next();
+                    }
+                    else {
+                        // if this route does not start with a slash, it is not a valid route
+                        return Err(dioxus_router::routable::RouteParseError {
+                            attempted_routes: Vec::new(),
+                        });
                     }
                     let mut errors = Vec::new();
 

+ 1 - 1
packages/router-macro/src/route_tree.rs

@@ -367,7 +367,7 @@ impl<'a> RouteTreeSegmentData<'a> {
                         let child_name = &child.ident;
 
                         quote! {
-                            let mut trailing = String::new();
+                            let mut trailing = String::from("/");
                             for seg in segments.clone() {
                                 trailing += seg;
                                 trailing += "/";