28 lines
890 B
Plaintext
28 lines
890 B
Plaintext
:title
|
|
request_query_path
|
|
|
|
:sig
|
|
String request_query_path(Request& context, String default_path = "index")
|
|
|
|
:see
|
|
request_query_route
|
|
request_context_params
|
|
route_path_sanitize
|
|
route_path_is_safe
|
|
parse_query
|
|
|
|
:content
|
|
Returns the first keyless query-string segment as a sanitized route path.
|
|
|
|
For a request such as `/?workspace/projects&theme=dark`, this returns `workspace/projects`.
|
|
|
|
When no keyless route is supplied, the result is `default_path`. When unsafe route input is supplied, the result is an empty string. Unsafe route input includes `.` or `..` segments, empty interior segments, backslashes, dots in filenames, or any character outside ASCII letters, digits, `_`, and `-`.
|
|
|
|
```cpp
|
|
String route_path = request_query_path(context);
|
|
if(route_path == "")
|
|
context.set_status(404, "Not Found");
|
|
```
|
|
|
|
The runtime-populated `context.params["ROUTE_PATH"]` uses the same sanitizer.
|