"env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"jsonwebtoken 5.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
strum = "0.14.0"
strum_macros = "0.14.0"
jsonwebtoken = "*"
-regex = "1"
+regex = "*"
+lazy_static = "*"
pub extern crate bcrypt;
pub extern crate regex;
#[macro_use] pub extern crate strum_macros;
-
+#[macro_use] pub extern crate lazy_static;
pub mod schema;
pub mod apub;
pub mod actions;
}
pub fn is_email_regex(test: &str) -> bool {
- let re = Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$").unwrap();
- re.is_match(test)
+ EMAIL_REGEX.is_match(test)
+}
+
+pub fn remove_slurs(test: &str) -> String {
+ SLUR_REGEX.replace_all(test, "*removed*").to_string()
+}
+
+pub fn has_slurs(test: &str) -> bool {
+ SLUR_REGEX.is_match(test)
}
#[cfg(test)]
mod tests {
- use {Settings, is_email_regex};
+ use {Settings, is_email_regex, remove_slurs, has_slurs};
#[test]
fn test_api() {
assert_eq!(Settings::get().api_endpoint(), "http://0.0.0.0/api/v1");
}
- #[test]
- fn test_email() {
+ #[test] fn test_email() {
assert!(is_email_regex("gush@gmail.com"));
assert!(!is_email_regex("nada_neutho"));
}
+
+ #[test] fn test_slur_filter() {
+ let test = "coons test dindu ladyboy tranny. This is a bunch of other safe text.".to_string();
+ let slur_free = "No slurs here";
+ assert_eq!(remove_slurs(&test), "*removed* test *removed* *removed* *removed*. This is a bunch of other safe text.".to_string());
+ assert!(has_slurs(&test));
+ assert!(!has_slurs(slur_free));
+ }
+}
+
+
+lazy_static! {
+ static ref EMAIL_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$").unwrap();
+ static ref SLUR_REGEX: Regex = Regex::new(r"(fag(g|got|tard)?|maricos?|cock\s?sucker(s|ing)?|\bnig(\b|g?(a|er)?s?)\b|dindu(s?)|mudslime?s?|kikes?|mongoloids?|towel\s*heads?|\bspi(c|k)s?\b|\bchinks?|niglets?|beaners?|\bnips?\b|\bcoons?\b|jungle\s*bunn(y|ies?)|jigg?aboo?s?|\bpakis?\b|rag\s*heads?|gooks?|cunts?|bitch(es|ing|y)?|puss(y|ies?)|twats?|feminazis?|whor(es?|ing)|\bslut(s|t?y)?|\btrann?(y|ies?)|ladyboy(s?))").unwrap();
}
+
use bcrypt::{verify};
use std::str::FromStr;
-use {Crud, Joinable, Likeable, Followable, establish_connection, naive_now, SortType};
+use {Crud, Joinable, Likeable, Followable, establish_connection, naive_now, SortType, has_slurs, remove_slurs};
use actions::community::*;
use actions::user::*;
use actions::post::*;
return self.error("Passwords do not match.");
}
+ if has_slurs(&self.username) {
+ return self.error("No slurs");
+ }
+
// Register the new user
let user_form = UserForm {
name: self.username.to_owned(),
}
};
+ if has_slurs(&self.name) ||
+ has_slurs(&self.title) ||
+ (self.description.is_some() && has_slurs(&self.description.to_owned().unwrap())) {
+ return self.error("No slurs");
+ }
+
let user_id = claims.id;
// When you create a community, make sure the user becomes a moderator and a follower
}
};
+ if has_slurs(&self.name) ||
+ (self.body.is_some() && has_slurs(&self.body.to_owned().unwrap())) {
+ return self.error("No slurs");
+ }
+
let user_id = claims.id;
let post_form = PostForm {
let user_id = claims.id;
+ let content_slurs_removed = remove_slurs(&self.content.to_owned());
+
let comment_form = CommentForm {
- content: self.content.to_owned(),
+ content: content_slurs_removed,
parent_id: self.parent_id.to_owned(),
post_id: self.post_id,
creator_id: user_id,
return self.error("Incorrect creator.");
}
+ let content_slurs_removed = remove_slurs(&self.content.to_owned());
+
let comment_form = CommentForm {
- content: self.content.to_owned(),
+ content: content_slurs_removed,
parent_id: self.parent_id,
post_id: self.post_id,
creator_id: user_id,
fn perform(&self, chat: &mut ChatServer, addr: usize) -> String {
+ if has_slurs(&self.name) ||
+ (self.body.is_some() && has_slurs(&self.body.to_owned().unwrap())) {
+ return self.error("No slurs");
+ }
+
let conn = establish_connection();
let claims = match Claims::decode(&self.auth) {
fn perform(&self, chat: &mut ChatServer, addr: usize) -> String {
+ if has_slurs(&self.name) || has_slurs(&self.title) {
+ return self.error("No slurs");
+ }
+
let conn = establish_connection();
let claims = match Claims::decode(&self.auth) {
if (msg.error) {
alert(msg.error);
this.state.loading = false;
+ this.setState(this.state);
return;
} else if (op == UserOperation.ListCategories){
let res: ListCategoriesResponse = msg;
<div class="form-group row">
<label class="col-sm-2 col-form-label">Username</label>
<div class="col-sm-10">
- <input type="text" class="form-control" value={this.state.registerForm.username} onInput={linkEvent(this, this.handleRegisterUsernameChange)} required minLength={3} />
+ <input type="text" class="form-control" value={this.state.registerForm.username} onInput={linkEvent(this, this.handleRegisterUsernameChange)} required minLength={3} pattern="[a-zA-Z0-9_]+" />
</div>
</div>
<div class="form-group row">
parseMessage(msg: any) {
let op: UserOperation = msgOp(msg);
if (msg.error) {
+ alert(msg.error);
this.state.loading = false;
+ this.setState(this.state);
return;
} else if (op == UserOperation.ListCommunities) {
let res: ListCommunitiesResponse = msg;