Skip to content

Commit

Permalink
Santize home description (#575)
Browse files Browse the repository at this point in the history
This was reverted in the past commit
  • Loading branch information
jacksongoode authored Dec 29, 2024
1 parent fed45f5 commit 8b9f719
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
6 changes: 2 additions & 4 deletions psst-gui/src/data/playlist.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::sync::Arc;

use druid::{im::Vector, Data, Lens};
use sanitize_html::rules::predefined::DEFAULT;
use sanitize_html::sanitize_str;
use serde::{Deserialize, Deserializer, Serialize};

use crate::data::utils::sanitize_html_string;
use crate::data::{user::PublicUser, Image, Promise, Track, TrackId};

#[derive(Clone, Debug, Data, Lens)]
Expand Down Expand Up @@ -98,6 +97,5 @@ where
D: Deserializer<'de>,
{
let description: String = String::deserialize(deserializer)?;
let sanitized = sanitize_str(&DEFAULT, &description).unwrap_or_default();
Ok(Arc::from(sanitized.replace("&amp;", "&")))
Ok(sanitize_html_string(&description))
}
7 changes: 7 additions & 0 deletions psst-gui/src/data/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::{
};

use druid::{im::Vector, Data, Lens};
use sanitize_html::rules::predefined::DEFAULT;
use sanitize_html::sanitize_str;
use serde::{Deserialize, Deserializer, Serialize};
use time::{Date, Month};

Expand Down Expand Up @@ -172,3 +174,8 @@ where
let opt = Option::deserialize(deserializer)?;
Ok(opt.unwrap_or_else(default_str))
}

pub fn sanitize_html_string(text: &str) -> Arc<str> {
let sanitized = sanitize_str(&DEFAULT, text).unwrap_or_default();
Arc::from(sanitized.replace("&amp;", "&"))
}
21 changes: 11 additions & 10 deletions psst-gui/src/webapi/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use psst_core::{
};

use crate::{
data::utils::sanitize_html_string,
data::{
self, Album, AlbumType, Artist, ArtistAlbums, ArtistInfo, ArtistLink, ArtistStats,
AudioAnalysis, Cached, Episode, EpisodeId, EpisodeLink, Image, MixedView, Nav, Page,
Expand Down Expand Up @@ -486,21 +487,21 @@ impl WebApi {
},
)),
description: {
let desc = item
.content
.data
.description
.as_deref()
.unwrap_or_default()
.to_string();
let desc = sanitize_html_string(
item.content
.data
.description
.as_deref()
.unwrap_or_default(),
);

// This is roughly 3 lines of description, truncated if too long
if desc.chars().count() > 55 {
desc.chars().take(52).collect::<String>() + "..."
Arc::from(desc.chars().take(52).collect::<String>() + "...")
} else {
desc
}
}
.into(),
},
track_count: item.content.data.attributes.as_ref().and_then(
|attrs| {
attrs
Expand Down

0 comments on commit 8b9f719

Please sign in to comment.