Skip to content

Commit

Permalink
fix(ui): support url encoded path in ui handler (#1354)
Browse files Browse the repository at this point in the history
* support-urlencode-path

* fix url encoding for error_message

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
wsxiaoys and autofix-ci[bot] authored Feb 2, 2024
1 parent f0c67f9 commit 2267083
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ee/tabby-webserver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ tower = { version = "0.4", features = ["util"] }
tower-http = { version = "0.4.0", features = ["fs", "trace"] }
tracing.workspace = true
unicase = "2.7.0"
urlencoding = "2.1.3"
uuid.workspace = true
validator = { version = "0.16.1", features = ["derive"] }

Expand Down
2 changes: 1 addition & 1 deletion ee/tabby-webserver/src/oauth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ fn match_auth_result(

fn make_error_redirect(provider: OAuthProvider, message: &str) -> Redirect {
let query = querystring::stringify(vec![
("error_message", message),
("error_message", urlencoding::encode(message).as_ref()),
(
"provider",
serde_json::to_string(&provider).unwrap().as_str(),
Expand Down
18 changes: 13 additions & 5 deletions ee/tabby-webserver/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@ where
T: Into<String>,
{
fn into_response(self) -> Response {
let make_404_response = || {
Response::builder()
.status(StatusCode::NOT_FOUND)
.body(boxed(Full::from(WebAssets::get("404.html").unwrap().data)))
.unwrap_or_else(|_| panic!("Invalid response"))
};

let path = self.0.into();
match WebAssets::get(path.as_str()) {
let Ok(decoded_path) = urlencoding::decode(&path) else {
return make_404_response();
};

match WebAssets::get(decoded_path.as_ref()) {
Some(content) => {
let body = boxed(Full::from(content.data));
let mime = mime_guess::from_path(path).first_or_octet_stream();
Expand All @@ -25,10 +36,7 @@ where
.body(body)
.unwrap_or_else(|_| panic!("Invalid response"))
}
None => Response::builder()
.status(StatusCode::NOT_FOUND)
.body(boxed(Full::from(WebAssets::get("404.html").unwrap().data)))
.unwrap_or_else(|_| panic!("Invalid response")),
None => make_404_response(),
}
}
}
Expand Down

0 comments on commit 2267083

Please sign in to comment.