aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2018-07-02 09:40:48 -0700
committerZeyla Hellyer <[email protected]>2018-07-02 09:40:48 -0700
commit0067c3335929325f54a3a0fe3693703e16de219c (patch)
tree119bb384af513eff15a2d93bf5b1b9e67c9289a0 /src
parentMake guild optional on Invites (diff)
downloadserenity-0067c3335929325f54a3a0fe3693703e16de219c.tar.xz
serenity-0067c3335929325f54a3a0fe3693703e16de219c.zip
Fix utils::is_nsfw string slicing
Removes string slicing on the input string, instead preferring to count chars and work off that information. Fixes channel names with unicode such as `général`. Fixes #342.
Diffstat (limited to 'src')
-rw-r--r--src/utils/mod.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index c48432e..5eba1ff 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -92,10 +92,12 @@ pub fn vecmap_to_json_map<K: PartialEq + ToString>(map: VecMap<K, Value>) -> Map
/// assert!(!utils::is_nsfw("nsfwstuff"));
/// ```
pub fn is_nsfw(name: &str) -> bool {
- if name.len() == 4 {
- &name[..4] == "nsfw"
- } else if name.len() > 4 {
- &name[..5] == "nsfw-"
+ let char_count = name.chars().count();
+
+ if char_count == 4 {
+ name == "nsfw"
+ } else if char_count > 4 {
+ name.starts_with("nsfw-")
} else {
false
}