commit a78ad43003ce55b31b7c6f81b6c2a9aa94b94c6b
parent 148965ab6316bed90a1bd1a727fc58134f021dbc
Author: Papayapaya <91221817+Papayapaya@users.noreply.github.com>
Date: Thu, 17 Nov 2022 12:51:09 -0800
add name cleaner stuff to main
Diffstat:
3 files changed, 74 insertions(+), 55 deletions(-)
diff --git a/name_cleaner.rs b/name_cleaner.rs
@@ -0,0 +1,53 @@
+//TODO: implement (make this return something instead of printing and use that value)
+///checks for invisible/zero-width characters in names and deletes them.
+pub fn main(){
+ //TODO next: check for initial and final whitespace
+ use std::char;
+ let disallowed_chars: [u32; 53] = [0x202e,0x0009,0x00AD,0x034F,0x061C,0x115F,0x1160,0x17B4,0x17B5,0x180E,0x2000,0x2001,0x2002,0x2003,0x2004,0x2005,0x2006,0x2007,0x2008,0x2009,0x200A,0x200B,0x200C,0x200D,0x200E,0x200F,0x202F,0x205F,0x2060,0x2061,0x2062,0x2063,0x2064,0x206A,0x206B,0x206C,0x206D,0x206E,0x206F,0x3000,0x2800,0x3164,0xFEFF,0xFFA0,0x1D159,0x1D173,0x1D174,0x1D175,0x1D176,0x1D177,0x1D178,0x1D179,0x1D17A];
+ let name_chars = name.chars(); //change this back to name.0.chars()
+ // chars() is already an iterator use chars().next() and chars().count() (hover for more info)
+ // println!("{}", name_chars);
+ let mut fixed_name = String::from("");
+ // let mut sanitized_name = String::from("");
+ let mut index = 0;
+ let mut to_keep:[bool; 32] = [true; 32]; //assuming 32 is the max name size - TODO: figure out how to not hardcode this in rust
+ // let mut first_char:bool = false;
+ // let mut last_char:usize = 0;
+ for i in name_chars{
+ for j in 0..disallowed_chars.len(){
+ if i == char::from_u32(disallowed_chars[j]).unwrap() {
+ to_keep[index] = false;
+ };
+ };
+ // if !first_char{
+ // if i == ' '{
+ // to_keep[index] = false;
+ // } else{
+ // first_char = true;
+ // };
+ // };
+ // if i != ' '{
+ // last_char = index;
+ // };
+ // index+=1;
+ // };
+ // if last_char < index{
+ // for i in to_keep{ // i is a bool bc its indexing tokeep
+ // if i > first_char{
+ // to_keep[i] = false;
+ // };
+ // };
+ // };
+ // index = 0;
+ // for i in name_chars{
+ if to_keep[index]{
+ fixed_name.push(i)
+ };
+ index += 1;
+ };
+ //sanitize leading and trailing whitespace
+ // while fixed_name[0] == ' '{
+ // fixed_name.remove(0);
+ // }
+ println!("{}", fixed_name);
+}
+\ No newline at end of file
diff --git a/scuttlebutt/src/main.rs b/scuttlebutt/src/main.rs
@@ -153,6 +153,26 @@ impl Api {
if hash.0.len() != 64 {
return BadRequest(PlainText("Invalid hash provided.".to_string()));
}
+
+ // name cleaning:
+ let disallowed_chars: [u32; 53] = [0x202e,0x0009,0x00AD,0x034F,0x061C,0x115F,0x1160,0x17B4,0x17B5,0x180E,0x2000,0x2001,0x2002,0x2003,0x2004,0x2005,0x2006,0x2007,0x2008,0x2009,0x200A,0x200B,0x200C,0x200D,0x200E,0x200F,0x202F,0x205F,0x2060,0x2061,0x2062,0x2063,0x2064,0x206A,0x206B,0x206C,0x206D,0x206E,0x206F,0x3000,0x2800,0x3164,0xFEFF,0xFFA0,0x1D159,0x1D173,0x1D174,0x1D175,0x1D176,0x1D177,0x1D178,0x1D179,0x1D17A];
+ let name_chars = name.chars();
+ let mut fixed_name = String::from("");
+ let mut index = 0;
+ let mut to_keep:[bool; 32] = [true; 32]; //assuming 32 is the max name size - TODO: figure out how to not hardcode this in rust
+ for i in name_chars{
+ for j in 0..disallowed_chars.len(){
+ if i == char::from_u32(disallowed_chars[j]).unwrap() {
+ to_keep[index] = false;
+ };
+ };
+ if to_keep[index]{
+ fixed_name.push(i)
+ };
+ index += 1;
+ };
+
+
let id = gen_id();
self.db.create_user(id, name.0.clone(), email.0.clone(), hash.0).unwrap();
self.db.create_user_groups(id).unwrap();
diff --git a/testable.rs b/testable.rs
@@ -1,54 +0,0 @@
-//TODO: implement (make this return something instead of printing and use that value)
-///checks for invisible/zero-width characters in names and deletes them.
-fn main(){
- //TODO next: check for initial and final whitespace
- use std::char;
- let name = " \u{202e}epIc​Gam\u{0009}e\u{1D174}r69 ";
- let disallowed_chars: [u32; 53] = [0x202e,0x0009,0x00AD,0x034F,0x061C,0x115F,0x1160,0x17B4,0x17B5,0x180E,0x2000,0x2001,0x2002,0x2003,0x2004,0x2005,0x2006,0x2007,0x2008,0x2009,0x200A,0x200B,0x200C,0x200D,0x200E,0x200F,0x202F,0x205F,0x2060,0x2061,0x2062,0x2063,0x2064,0x206A,0x206B,0x206C,0x206D,0x206E,0x206F,0x3000,0x2800,0x3164,0xFEFF,0xFFA0,0x1D159,0x1D173,0x1D174,0x1D175,0x1D176,0x1D177,0x1D178,0x1D179,0x1D17A];
- let name_chars = name.chars(); //change this back to name.0.chars()
- // chars() is already an iterator use chars().next() and chars().count() (hover for more info)
- // println!("{}", name_chars);
- let mut fixed_name = String::from("");
- // let mut sanitized_name = String::from("");
- let mut index = 0;
- let mut to_keep:[bool; 32] = [true; 32]; //assuming 32 is the max name size - TODO: figure out how to not hardcode this in rust
- // let mut first_char:bool = false;
- // let mut last_char:usize = 0;
- for i in name_chars{
- for j in 0..disallowed_chars.len(){
- if i == char::from_u32(disallowed_chars[j]).unwrap() {
- to_keep[index] = false;
- };
- };
- // if !first_char{
- // if i == ' '{
- // to_keep[index] = false;
- // } else{
- // first_char = true;
- // };
- // };
- // if i != ' '{
- // last_char = index;
- // };
- // index+=1;
- // };
- // if last_char < index{
- // for i in to_keep{ // i is a bool bc its indexing tokeep
- // if i > first_char{
- // to_keep[i] = false;
- // };
- // };
- // };
- // index = 0;
- // for i in name_chars{
- if to_keep[index]{
- fixed_name.push(i)
- };
- index += 1;
- };
- //sanitize leading and trailing whitespace
- // while fixed_name[0] == ' '{
- // fixed_name.remove(0);
- // }
- println!("{}", fixed_name);
-}
-\ No newline at end of file