We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Bug: route with path parameters matches longer paths
### Description

A route registered for `/{param:str}`, in addition to matching `/foo` matches also `/foo/bar` (but not `/foo/bar/baz`).

### URL to code causing the issue

_No response_

### MCVE

```python
from litestar import Litestar, get


@get("/{name:str}")
async def hello_world(name: str) -> str:
    return f"Hello, {name}!"


app = Litestar([hello_world])
```


### Steps to reproduce

```bash
✗ http -b 'localhost:8000/jon'
Hello, jon!


✗ http -b 'localhost:8000/jon/bon'
Hello, jon!


✗ http -b 'localhost:8000/jon/bon/jovi'
{
    "detail": "Not Found",
    "status_code": 404
}
```
```


### Screenshots

```bash
"![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"
```


### Logs

_No response_

### Litestar Version

Main branch

### Platform

- [ ] Linux
- [ ] Mac
- [ ] Windows
- [ ] Other (Please specify in the description above)

<!-- POLAR PLEDGE BADGE START -->
## Funding
* If you would like to see an issue prioritized, make a pledge towards it!
* We receive the pledge once the issue is completed & verified

<a href="https://polar.sh/litestar-org/litestar/issues/1830">
<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://polar.sh/api/github/litestar-org/litestar/issues/1830/pledge.svg?darkmode=1">
  <img alt="Fund with Polar" src="https://polar.sh/api/github/litestar-org/litestar/issues/1830/pledge.svg">
</picture>
</a>
<!-- POLAR PLEDGE BADGE END -->


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `litestar/_asgi/routing_trie/traversal.py`
Content:
```
1 from __future__ import annotations
2 
3 from functools import lru_cache
4 from typing import TYPE_CHECKING, Any, Pattern
5 
6 from litestar._asgi.routing_trie.types import PathParameterSentinel
7 from litestar.exceptions import MethodNotAllowedException, NotFoundException
8 from litestar.utils import normalize_path
9 
10 __all__ = ("parse_node_handlers", "parse_path_params", "parse_path_to_route", "traverse_route_map")
11 
12 
13 if TYPE_CHECKING:
14     from litestar._asgi.routing_trie.types import ASGIHandlerTuple, RouteTrieNode
15     from litestar.types import ASGIApp, Method, RouteHandlerType
16     from litestar.types.internal_types import PathParameterDefinition
17 
18 
19 def traverse_route_map(
20     root_node: RouteTrieNode,
21     path: str,
22 ) -> tuple[RouteTrieNode, list[str], str]:
23     """Traverses the application route mapping and retrieves the correct node for the request url.
24 
25     Args:
26         root_node: The root trie node.
27         path: The request's path.
28 
29     Raises:
30         NotFoundException: If no correlating node is found.
31 
32     Returns:
33         A tuple containing the target RouteMapNode and a list containing all path parameter values.
34     """
35     current_node = root_node
36     path_params: list[str] = []
37     path_components = [p for p in path.split("/") if p]
38 
39     for i, component in enumerate(path_components):
40         if component in current_node.child_keys:
41             current_node = current_node.children[component]
42             continue
43 
44         if current_node.is_path_param_node:
45             current_node = current_node.children[PathParameterSentinel]
46 
47             if current_node.is_path_type:
48                 path_params.append(normalize_path("/".join(path_components[i:])))
49                 break
50 
51             path_params.append(component)
52             continue
53 
54         if i != len(path_components) - 1 or not current_node.children:
55             raise NotFoundException()
56 
57     if not current_node.asgi_handlers:
58         raise NotFoundException()
59 
60     return current_node, path_params, path
61 
62 
63 def parse_node_handlers(
64     node: RouteTrieNode,
65     method: Method | None,
66 ) -> ASGIHandlerTuple:
67     """Retrieve the handler tuple from the node.
68 
69     Args:
70         node: The trie node to parse.
71         method: The scope's method.
72 
73     Raises:
74         KeyError: If no matching method is found.
75 
76     Returns:
77         An ASGI Handler tuple.
78     """
79 
80     if node.is_asgi:
81         return node.asgi_handlers["asgi"]
82     if method:
83         return node.asgi_handlers[method]
84     return node.asgi_handlers["websocket"]
85 
86 
87 @lru_cache(1024)
88 def parse_path_params(
89     parameter_definitions: tuple[PathParameterDefinition, ...], path_param_values: tuple[str, ...]
90 ) -> dict[str, Any]:
91     """Parse path parameters into a dictionary of values.
92 
93     Args:
94         parameter_definitions: The parameter definitions tuple from the route.
95         path_param_values: The string values extracted from the url
96 
97     Raises:
98         ValueError: If any of path parameters can not be parsed into a value.
99 
100     Returns:
101         A dictionary of parsed path parameters.
102     """
103     return {
104         param_definition.name: param_definition.parser(value) if param_definition.parser else value
105         for param_definition, value in zip(parameter_definitions, path_param_values)
106     }
107 
108 
109 def parse_path_to_route(
110     method: Method | None,
111     mount_paths_regex: Pattern | None,
112     mount_routes: dict[str, RouteTrieNode],
113     path: str,
114     plain_routes: set[str],
115     root_node: RouteTrieNode,
116 ) -> tuple[ASGIApp, RouteHandlerType, str, dict[str, Any]]:
117     """Given a scope object, retrieve the asgi_handlers and is_mount boolean values from correct trie node.
118 
119     Args:
120         method: The scope's method, if any.
121         root_node: The root trie node.
122         path: The path to resolve scope instance.
123         plain_routes: The set of plain routes.
124         mount_routes: Mapping of mount routes to trie nodes.
125         mount_paths_regex: A compiled regex to match the mount routes.
126 
127     Raises:
128         MethodNotAllowedException: if no matching method is found.
129         NotFoundException: If no correlating node is found or if path params can not be parsed into values according to the node definition.
130 
131     Returns:
132         A tuple containing the stack of middlewares and the route handler that is wrapped by it.
133     """
134 
135     try:
136         if path in plain_routes:
137             asgi_app, handler = parse_node_handlers(node=root_node.children[path], method=method)
138             return asgi_app, handler, path, {}
139 
140         if mount_paths_regex and (match := mount_paths_regex.search(path)):
141             mount_path = path[match.start() : match.end()]
142             mount_node = mount_routes[mount_path]
143             remaining_path = path[match.end() :]
144             # since we allow regular handlers under static paths, we must validate that the request does not match
145             # any such handler.
146             if not mount_node.children or all(
147                 sub_route not in path for sub_route in mount_node.children  # type: ignore
148             ):
149                 asgi_app, handler = parse_node_handlers(node=mount_node, method=method)
150                 remaining_path = remaining_path or "/"
151                 if not mount_node.is_static:
152                     remaining_path = remaining_path if remaining_path.endswith("/") else f"{remaining_path}/"
153                 return asgi_app, handler, remaining_path, {}
154 
155         node, path_parameters, path = traverse_route_map(
156             root_node=root_node,
157             path=path,
158         )
159         asgi_app, handler = parse_node_handlers(node=node, method=method)
160         key = method or ("asgi" if node.is_asgi else "websocket")
161         parsed_path_parameters = parse_path_params(node.path_parameters[key], tuple(path_parameters))
162 
163         return (
164             asgi_app,
165             handler,
166             path,
167             parsed_path_parameters,
168         )
169     except KeyError as e:
170         raise MethodNotAllowedException() from e
171     except ValueError as e:
172         raise NotFoundException() from e
173
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/litestar/_asgi/routing_trie/traversal.py b/litestar/_asgi/routing_trie/traversal.py
--- a/litestar/_asgi/routing_trie/traversal.py
+++ b/litestar/_asgi/routing_trie/traversal.py
@@ -51,8 +51,7 @@
             path_params.append(component)
             continue
 
-        if i != len(path_components) - 1 or not current_node.children:
-            raise NotFoundException()
+        raise NotFoundException()
 
     if not current_node.asgi_handlers:
         raise NotFoundException()

{"golden_diff": "diff --git a/litestar/_asgi/routing_trie/traversal.py b/litestar/_asgi/routing_trie/traversal.py\n--- a/litestar/_asgi/routing_trie/traversal.py\n+++ b/litestar/_asgi/routing_trie/traversal.py\n@@ -51,8 +51,7 @@\n             path_params.append(component)\n             continue\n \n-        if i != len(path_components) - 1 or not current_node.children:\n-            raise NotFoundException()\n+        raise NotFoundException()\n \n     if not current_node.asgi_handlers:\n         raise NotFoundException()\n", "issue": "Bug: route with path parameters matches longer paths\n### Description\n\nA route registered for `/{param:str}`, in addition to matching `/foo` matches also `/foo/bar` (but not `/foo/bar/baz`).\n\n### URL to code causing the issue\n\n_No response_\n\n### MCVE\n\n```python\nfrom litestar import Litestar, get\r\n\r\n\r\n@get(\"/{name:str}\")\r\nasync def hello_world(name: str) -> str:\r\n    return f\"Hello, {name}!\"\r\n\r\n\r\napp = Litestar([hello_world])\n```\n\n\n### Steps to reproduce\n\n```bash\n\u2717 http -b 'localhost:8000/jon'\r\nHello, jon!\r\n\r\n\r\n\u2717 http -b 'localhost:8000/jon/bon'\r\nHello, jon!\r\n\r\n\r\n\u2717 http -b 'localhost:8000/jon/bon/jovi'\r\n{\r\n    \"detail\": \"Not Found\",\r\n    \"status_code\": 404\r\n}\r\n```\n```\n\n\n### Screenshots\n\n```bash\n\"![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)\"\n```\n\n\n### Logs\n\n_No response_\n\n### Litestar Version\n\nMain branch\n\n### Platform\n\n- [ ] Linux\n- [ ] Mac\n- [ ] Windows\n- [ ] Other (Please specify in the description above)\n\n<!-- POLAR PLEDGE BADGE START -->\n## Funding\n* If you would like to see an issue prioritized, make a pledge towards it!\n* We receive the pledge once the issue is completed & verified\n\n<a href=\"https://polar.sh/litestar-org/litestar/issues/1830\">\n<picture>\n  <source media=\"(prefers-color-scheme: dark)\" srcset=\"https://polar.sh/api/github/litestar-org/litestar/issues/1830/pledge.svg?darkmode=1\">\n  <img alt=\"Fund with Polar\" src=\"https://polar.sh/api/github/litestar-org/litestar/issues/1830/pledge.svg\">\n</picture>\n</a>\n<!-- POLAR PLEDGE BADGE END -->\n\n", "before_files": [{"content": "from __future__ import annotations\n\nfrom functools import lru_cache\nfrom typing import TYPE_CHECKING, Any, Pattern\n\nfrom litestar._asgi.routing_trie.types import PathParameterSentinel\nfrom litestar.exceptions import MethodNotAllowedException, NotFoundException\nfrom litestar.utils import normalize_path\n\n__all__ = (\"parse_node_handlers\", \"parse_path_params\", \"parse_path_to_route\", \"traverse_route_map\")\n\n\nif TYPE_CHECKING:\n    from litestar._asgi.routing_trie.types import ASGIHandlerTuple, RouteTrieNode\n    from litestar.types import ASGIApp, Method, RouteHandlerType\n    from litestar.types.internal_types import PathParameterDefinition\n\n\ndef traverse_route_map(\n    root_node: RouteTrieNode,\n    path: str,\n) -> tuple[RouteTrieNode, list[str], str]:\n    \"\"\"Traverses the application route mapping and retrieves the correct node for the request url.\n\n    Args:\n        root_node: The root trie node.\n        path: The request's path.\n\n    Raises:\n        NotFoundException: If no correlating node is found.\n\n    Returns:\n        A tuple containing the target RouteMapNode and a list containing all path parameter values.\n    \"\"\"\n    current_node = root_node\n    path_params: list[str] = []\n    path_components = [p for p in path.split(\"/\") if p]\n\n    for i, component in enumerate(path_components):\n        if component in current_node.child_keys:\n            current_node = current_node.children[component]\n            continue\n\n        if current_node.is_path_param_node:\n            current_node = current_node.children[PathParameterSentinel]\n\n            if current_node.is_path_type:\n                path_params.append(normalize_path(\"/\".join(path_components[i:])))\n                break\n\n            path_params.append(component)\n            continue\n\n        if i != len(path_components) - 1 or not current_node.children:\n            raise NotFoundException()\n\n    if not current_node.asgi_handlers:\n        raise NotFoundException()\n\n    return current_node, path_params, path\n\n\ndef parse_node_handlers(\n    node: RouteTrieNode,\n    method: Method | None,\n) -> ASGIHandlerTuple:\n    \"\"\"Retrieve the handler tuple from the node.\n\n    Args:\n        node: The trie node to parse.\n        method: The scope's method.\n\n    Raises:\n        KeyError: If no matching method is found.\n\n    Returns:\n        An ASGI Handler tuple.\n    \"\"\"\n\n    if node.is_asgi:\n        return node.asgi_handlers[\"asgi\"]\n    if method:\n        return node.asgi_handlers[method]\n    return node.asgi_handlers[\"websocket\"]\n\n\n@lru_cache(1024)\ndef parse_path_params(\n    parameter_definitions: tuple[PathParameterDefinition, ...], path_param_values: tuple[str, ...]\n) -> dict[str, Any]:\n    \"\"\"Parse path parameters into a dictionary of values.\n\n    Args:\n        parameter_definitions: The parameter definitions tuple from the route.\n        path_param_values: The string values extracted from the url\n\n    Raises:\n        ValueError: If any of path parameters can not be parsed into a value.\n\n    Returns:\n        A dictionary of parsed path parameters.\n    \"\"\"\n    return {\n        param_definition.name: param_definition.parser(value) if param_definition.parser else value\n        for param_definition, value in zip(parameter_definitions, path_param_values)\n    }\n\n\ndef parse_path_to_route(\n    method: Method | None,\n    mount_paths_regex: Pattern | None,\n    mount_routes: dict[str, RouteTrieNode],\n    path: str,\n    plain_routes: set[str],\n    root_node: RouteTrieNode,\n) -> tuple[ASGIApp, RouteHandlerType, str, dict[str, Any]]:\n    \"\"\"Given a scope object, retrieve the asgi_handlers and is_mount boolean values from correct trie node.\n\n    Args:\n        method: The scope's method, if any.\n        root_node: The root trie node.\n        path: The path to resolve scope instance.\n        plain_routes: The set of plain routes.\n        mount_routes: Mapping of mount routes to trie nodes.\n        mount_paths_regex: A compiled regex to match the mount routes.\n\n    Raises:\n        MethodNotAllowedException: if no matching method is found.\n        NotFoundException: If no correlating node is found or if path params can not be parsed into values according to the node definition.\n\n    Returns:\n        A tuple containing the stack of middlewares and the route handler that is wrapped by it.\n    \"\"\"\n\n    try:\n        if path in plain_routes:\n            asgi_app, handler = parse_node_handlers(node=root_node.children[path], method=method)\n            return asgi_app, handler, path, {}\n\n        if mount_paths_regex and (match := mount_paths_regex.search(path)):\n            mount_path = path[match.start() : match.end()]\n            mount_node = mount_routes[mount_path]\n            remaining_path = path[match.end() :]\n            # since we allow regular handlers under static paths, we must validate that the request does not match\n            # any such handler.\n            if not mount_node.children or all(\n                sub_route not in path for sub_route in mount_node.children  # type: ignore\n            ):\n                asgi_app, handler = parse_node_handlers(node=mount_node, method=method)\n                remaining_path = remaining_path or \"/\"\n                if not mount_node.is_static:\n                    remaining_path = remaining_path if remaining_path.endswith(\"/\") else f\"{remaining_path}/\"\n                return asgi_app, handler, remaining_path, {}\n\n        node, path_parameters, path = traverse_route_map(\n            root_node=root_node,\n            path=path,\n        )\n        asgi_app, handler = parse_node_handlers(node=node, method=method)\n        key = method or (\"asgi\" if node.is_asgi else \"websocket\")\n        parsed_path_parameters = parse_path_params(node.path_parameters[key], tuple(path_parameters))\n\n        return (\n            asgi_app,\n            handler,\n            path,\n            parsed_path_parameters,\n        )\n    except KeyError as e:\n        raise MethodNotAllowedException() from e\n    except ValueError as e:\n        raise NotFoundException() from e\n", "path": "litestar/_asgi/routing_trie/traversal.py"}], "after_files": [{"content": "from __future__ import annotations\n\nfrom functools import lru_cache\nfrom typing import TYPE_CHECKING, Any, Pattern\n\nfrom litestar._asgi.routing_trie.types import PathParameterSentinel\nfrom litestar.exceptions import MethodNotAllowedException, NotFoundException\nfrom litestar.utils import normalize_path\n\n__all__ = (\"parse_node_handlers\", \"parse_path_params\", \"parse_path_to_route\", \"traverse_route_map\")\n\n\nif TYPE_CHECKING:\n    from litestar._asgi.routing_trie.types import ASGIHandlerTuple, RouteTrieNode\n    from litestar.types import ASGIApp, Method, RouteHandlerType\n    from litestar.types.internal_types import PathParameterDefinition\n\n\ndef traverse_route_map(\n    root_node: RouteTrieNode,\n    path: str,\n) -> tuple[RouteTrieNode, list[str], str]:\n    \"\"\"Traverses the application route mapping and retrieves the correct node for the request url.\n\n    Args:\n        root_node: The root trie node.\n        path: The request's path.\n\n    Raises:\n        NotFoundException: If no correlating node is found.\n\n    Returns:\n        A tuple containing the target RouteMapNode and a list containing all path parameter values.\n    \"\"\"\n    current_node = root_node\n    path_params: list[str] = []\n    path_components = [p for p in path.split(\"/\") if p]\n\n    for i, component in enumerate(path_components):\n        if component in current_node.child_keys:\n            current_node = current_node.children[component]\n            continue\n\n        if current_node.is_path_param_node:\n            current_node = current_node.children[PathParameterSentinel]\n\n            if current_node.is_path_type:\n                path_params.append(normalize_path(\"/\".join(path_components[i:])))\n                break\n\n            path_params.append(component)\n            continue\n\n        raise NotFoundException()\n\n    if not current_node.asgi_handlers:\n        raise NotFoundException()\n\n    return current_node, path_params, path\n\n\ndef parse_node_handlers(\n    node: RouteTrieNode,\n    method: Method | None,\n) -> ASGIHandlerTuple:\n    \"\"\"Retrieve the handler tuple from the node.\n\n    Args:\n        node: The trie node to parse.\n        method: The scope's method.\n\n    Raises:\n        KeyError: If no matching method is found.\n\n    Returns:\n        An ASGI Handler tuple.\n    \"\"\"\n\n    if node.is_asgi:\n        return node.asgi_handlers[\"asgi\"]\n    if method:\n        return node.asgi_handlers[method]\n    return node.asgi_handlers[\"websocket\"]\n\n\n@lru_cache(1024)\ndef parse_path_params(\n    parameter_definitions: tuple[PathParameterDefinition, ...], path_param_values: tuple[str, ...]\n) -> dict[str, Any]:\n    \"\"\"Parse path parameters into a dictionary of values.\n\n    Args:\n        parameter_definitions: The parameter definitions tuple from the route.\n        path_param_values: The string values extracted from the url\n\n    Raises:\n        ValueError: If any of path parameters can not be parsed into a value.\n\n    Returns:\n        A dictionary of parsed path parameters.\n    \"\"\"\n    return {\n        param_definition.name: param_definition.parser(value) if param_definition.parser else value\n        for param_definition, value in zip(parameter_definitions, path_param_values)\n    }\n\n\ndef parse_path_to_route(\n    method: Method | None,\n    mount_paths_regex: Pattern | None,\n    mount_routes: dict[str, RouteTrieNode],\n    path: str,\n    plain_routes: set[str],\n    root_node: RouteTrieNode,\n) -> tuple[ASGIApp, RouteHandlerType, str, dict[str, Any]]:\n    \"\"\"Given a scope object, retrieve the asgi_handlers and is_mount boolean values from correct trie node.\n\n    Args:\n        method: The scope's method, if any.\n        root_node: The root trie node.\n        path: The path to resolve scope instance.\n        plain_routes: The set of plain routes.\n        mount_routes: Mapping of mount routes to trie nodes.\n        mount_paths_regex: A compiled regex to match the mount routes.\n\n    Raises:\n        MethodNotAllowedException: if no matching method is found.\n        NotFoundException: If no correlating node is found or if path params can not be parsed into values according to the node definition.\n\n    Returns:\n        A tuple containing the stack of middlewares and the route handler that is wrapped by it.\n    \"\"\"\n\n    try:\n        if path in plain_routes:\n            asgi_app, handler = parse_node_handlers(node=root_node.children[path], method=method)\n            return asgi_app, handler, path, {}\n\n        if mount_paths_regex and (match := mount_paths_regex.search(path)):\n            mount_path = path[match.start() : match.end()]\n            mount_node = mount_routes[mount_path]\n            remaining_path = path[match.end() :]\n            # since we allow regular handlers under static paths, we must validate that the request does not match\n            # any such handler.\n            if not mount_node.children or all(\n                sub_route not in path for sub_route in mount_node.children  # type: ignore\n            ):\n                asgi_app, handler = parse_node_handlers(node=mount_node, method=method)\n                remaining_path = remaining_path or \"/\"\n                if not mount_node.is_static:\n                    remaining_path = remaining_path if remaining_path.endswith(\"/\") else f\"{remaining_path}/\"\n                return asgi_app, handler, remaining_path, {}\n\n        node, path_parameters, path = traverse_route_map(\n            root_node=root_node,\n            path=path,\n        )\n        asgi_app, handler = parse_node_handlers(node=node, method=method)\n        key = method or (\"asgi\" if node.is_asgi else \"websocket\")\n        parsed_path_parameters = parse_path_params(node.path_parameters[key], tuple(path_parameters))\n\n        return (\n            asgi_app,\n            handler,\n            path,\n            parsed_path_parameters,\n        )\n    except KeyError as e:\n        raise MethodNotAllowedException() from e\n    except ValueError as e:\n        raise NotFoundException() from e\n", "path": "litestar/_asgi/routing_trie/traversal.py"}]}