瀏覽代碼

Fix custom routes on Windows (#389)

Nikhil Rao 2 年之前
父節點
當前提交
2b7e2ecf30
共有 2 個文件被更改,包括 25 次插入2 次删除
  1. 6 2
      pynecone/utils.py
  2. 19 0
      tests/test_utils.py

+ 6 - 2
pynecone/utils.py

@@ -893,9 +893,13 @@ def format_route(route: str) -> str:
     Returns:
     Returns:
         The formatted route.
         The formatted route.
     """
     """
-    route = route.strip(os.path.sep)
+    # If the route is empty, return the index route.
+    if route == "":
+        return constants.INDEX_ROUTE
+
+    route = route.strip("/")
     route = to_snake_case(route).replace("_", "-")
     route = to_snake_case(route).replace("_", "-")
-    return constants.INDEX_ROUTE if route == "" else route
+    return route
 
 
 
 
 def format_cond(
 def format_cond(

+ 19 - 0
tests/test_utils.py

@@ -206,6 +206,25 @@ def test_is_generic_alias(cls: type, expected: bool):
     assert utils.is_generic_alias(cls) == expected
     assert utils.is_generic_alias(cls) == expected
 
 
 
 
+@pytest.mark.parametrize(
+    "route,expected",
+    [
+        ("", "index"),
+        ("custom-route", "custom-route"),
+        ("custom-route/", "custom-route"),
+        ("/custom-route", "custom-route"),
+    ],
+)
+def test_format_route(route: str, expected: bool):
+    """Test formatting a route.
+
+    Args:
+        route: The route to format.
+        expected: The expected formatted route.
+    """
+    assert utils.format_route(route) == expected
+
+
 def test_setup_frontend(tmp_path, mocker):
 def test_setup_frontend(tmp_path, mocker):
     """Test checking if assets content have been
     """Test checking if assets content have been
     copied into the .web/public folder
     copied into the .web/public folder