Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
Validate emoji name length before saving to database
Browse files Browse the repository at this point in the history
  • Loading branch information
silverpill committed Apr 6, 2023
1 parent 970071a commit e950189
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- Added missing `CHECK` constraints to database tables.
- Validate object ID length before saving post to database.
- Validate emoji name length before saving to database.

## [1.19.1] - 2023-03-31

Expand Down
4 changes: 4 additions & 0 deletions src/validators/emojis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use regex::Regex;
use crate::errors::ValidationError;

const EMOJI_NAME_RE: &str = r"^[a-zA-Z0-9._-]+$";
const EMOJI_NAME_SIZE_MAX: usize = 100; // database column limit
pub const EMOJI_MAX_SIZE: usize = 500 * 1000; // 500 kB
pub const EMOJI_LOCAL_MAX_SIZE: usize = 50 * 1000; // 50 kB
pub const EMOJI_MEDIA_TYPES: [&str; 4] = [
Expand All @@ -17,6 +18,9 @@ pub fn validate_emoji_name(emoji_name: &str) -> Result<(), ValidationError> {
if !name_re.is_match(emoji_name) {
return Err(ValidationError("invalid emoji name"));
};
if emoji_name.len() > EMOJI_NAME_SIZE_MAX {
return Err(ValidationError("emoji name is too long"));
};
Ok(())
}

Expand Down

0 comments on commit e950189

Please sign in to comment.