aboutsummaryrefslogtreecommitdiff
path: root/azalea-chat/src/text_component.rs
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-chat/src/text_component.rs')
-rw-r--r--azalea-chat/src/text_component.rs35
1 files changed, 34 insertions, 1 deletions
diff --git a/azalea-chat/src/text_component.rs b/azalea-chat/src/text_component.rs
index db1b4edf..7332adfa 100644
--- a/azalea-chat/src/text_component.rs
+++ b/azalea-chat/src/text_component.rs
@@ -146,7 +146,7 @@ mod tests {
use crate::style::Ansi;
#[test]
- fn test_hypixel_motd() {
+ fn test_hypixel_motd_ansi() {
let component =
TextComponent::new("§aHypixel Network §c[1.8-1.18]\n§b§lHAPPY HOLIDAYS".to_string())
.get();
@@ -164,6 +164,39 @@ mod tests {
}
#[test]
+ fn test_hypixel_motd_html() {
+ let component =
+ TextComponent::new("§aHypixel Network §c[1.8-1.18]\n§b§lHAPPY HOLIDAYS".to_string())
+ .get();
+
+ assert_eq!(
+ component.to_html(),
+ format!(
+ "{GREEN}Hypixel Network {END_SPAN}{RED}[1.8-1.18]<br>{END_SPAN}{BOLD_AQUA}HAPPY HOLIDAYS{END_SPAN}",
+ END_SPAN = "</span>",
+ GREEN = "<span style=\"color: #55FF55;\">",
+ RED = "<span style=\"color: #FF5555;\">",
+ BOLD_AQUA = "<span style=\"color: #55FFFF;font-weight: bold;\">",
+ )
+ );
+ }
+
+ #[test]
+ fn test_xss_html() {
+ let component = TextComponent::new("§a<b>&\n§b</b>".to_string()).get();
+
+ assert_eq!(
+ component.to_html(),
+ format!(
+ "{GREEN}&lt;b&gt;&amp;<br>{END_SPAN}{AQUA}&lt;/b&gt;{END_SPAN}",
+ END_SPAN = "</span>",
+ GREEN = "<span style=\"color: #55FF55;\">",
+ AQUA = "<span style=\"color: #55FFFF;\">",
+ )
+ );
+ }
+
+ #[test]
fn test_legacy_color_code_to_component() {
let component = TextComponent::new("§lHello §r§1w§2o§3r§4l§5d".to_string()).get();
assert_eq!(