From 57c8f8573125d5964b8a81b67d64629e0e34fd82 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Sun, 15 Sep 2024 17:45:57 +0600 Subject: [PATCH] fix: playlist displaying descriptions unescaped html #1784 --- lib/components/playbutton_card.dart | 2 +- .../tracks_view/sections/header/flexible_header.dart | 4 +++- lib/extensions/string.dart | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/components/playbutton_card.dart b/lib/components/playbutton_card.dart index d540d31e..ae9050d8 100644 --- a/lib/components/playbutton_card.dart +++ b/lib/components/playbutton_card.dart @@ -58,7 +58,7 @@ class PlaybuttonCard extends HookWidget { others: 15, ); - var unescapeHtml = description?.unescapeHtml(); + final unescapeHtml = description?.unescapeHtml().cleanHtml(); return Container( constraints: BoxConstraints(maxWidth: size), margin: margin, diff --git a/lib/components/tracks_view/sections/header/flexible_header.dart b/lib/components/tracks_view/sections/header/flexible_header.dart index 6845cc3e..508d289c 100644 --- a/lib/components/tracks_view/sections/header/flexible_header.dart +++ b/lib/components/tracks_view/sections/header/flexible_header.dart @@ -128,7 +128,9 @@ class TrackViewFlexHeader extends HookConsumerWidget { if (props.description != null && props.description!.isNotEmpty) Text( - props.description!.unescapeHtml(), + props.description! + .unescapeHtml() + .cleanHtml(), style: defaultTextStyle.style.copyWith( color: palette.bodyTextColor, diff --git a/lib/extensions/string.dart b/lib/extensions/string.dart index d3706f3f..94123fe3 100644 --- a/lib/extensions/string.dart +++ b/lib/extensions/string.dart @@ -1,12 +1,15 @@ import 'package:html_unescape/html_unescape.dart'; +import 'package:html/parser.dart'; final htmlEscape = HtmlUnescape(); extension UnescapeHtml on String { + String cleanHtml() => parse("

$this

").documentElement!.text; String unescapeHtml() => htmlEscape.convert(this); } extension NullableUnescapeHtml on String? { + String? cleanHtml() => this?.cleanHtml(); String? unescapeHtml() => this?.unescapeHtml(); }