forked from deadvey/button
String -> str
This commit is contained in:
+7
-19
@@ -16,7 +16,7 @@ use axum::
|
||||
State,
|
||||
ws::{Message, WebSocket, WebSocketUpgrade},
|
||||
},
|
||||
response::{Html, IntoResponse},
|
||||
response::IntoResponse,
|
||||
routing::get,
|
||||
};
|
||||
use tokio::
|
||||
@@ -370,7 +370,6 @@ async fn handle_socket
|
||||
)
|
||||
{
|
||||
let mut value: u32 = 0;
|
||||
let msg: String;
|
||||
|
||||
let Some(name) = socket.next().await else
|
||||
{
|
||||
@@ -381,7 +380,7 @@ async fn handle_socket
|
||||
{
|
||||
Message::Text(text) =>
|
||||
{
|
||||
Arc::from(validate_name(text.to_string()))
|
||||
Arc::from(validate_name(&text))
|
||||
}
|
||||
_ => Arc::from("anon"),
|
||||
};
|
||||
@@ -443,34 +442,23 @@ async fn handle_socket
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_name(input: String) -> String {
|
||||
fn validate_name(input: &str) -> &str {
|
||||
let input = input.trim();
|
||||
if input == "null"
|
||||
{
|
||||
return "anon".to_string();
|
||||
return "anon";
|
||||
}
|
||||
// Length check
|
||||
if input.is_empty() || input.len() > 32 {
|
||||
return "anon".to_string();
|
||||
return "anon";
|
||||
}
|
||||
|
||||
// Allow only letters, numbers, _ and -
|
||||
let re = Regex::new(r"^[a-zA-Z0-9_-]+$").unwrap();
|
||||
|
||||
if re.is_match(input) {
|
||||
input.to_string()
|
||||
input
|
||||
} else {
|
||||
"anon".to_string()
|
||||
"anon"
|
||||
}
|
||||
}
|
||||
|
||||
// static routes
|
||||
async fn index() -> Html<&'static str>
|
||||
{
|
||||
Html(include_str!("../index.html"))
|
||||
}
|
||||
|
||||
async fn leaderboard() -> Html<&'static str>
|
||||
{
|
||||
Html(include_str!("../leaderboard.html"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user