mirror of
https://github.com/Dinnerbone/mcstatus.git
synced 2026-04-05 03:21:23 +08:00
Strip HTML color codes from description parsing
This commit is contained in:
@@ -253,10 +253,13 @@ class PingResponse:
|
||||
for entry in entries:
|
||||
for style_key, style_val in STYLE_MAP.items():
|
||||
if entry.get(style_key):
|
||||
if isinstance(style_val, dict):
|
||||
style_val = style_val[entry[style_key]]
|
||||
try:
|
||||
if isinstance(style_val, dict):
|
||||
style_val = style_val[entry[style_key]]
|
||||
|
||||
description += f"§{style_val}"
|
||||
description += f"§{style_val}"
|
||||
except KeyError:
|
||||
pass # ignoring these key errors strips out html color codes
|
||||
description += entry.get("text", "")
|
||||
|
||||
return description + end
|
||||
|
||||
@@ -110,6 +110,65 @@ class TestPingResponse:
|
||||
}
|
||||
)
|
||||
|
||||
def test_parse_description_strips_html_color_codes(self):
|
||||
out = PingResponse._parse_description(
|
||||
{
|
||||
"extra": [
|
||||
{"text": " "},
|
||||
{"strikethrough": True, "color": "#b3eeff", "text": "="},
|
||||
{"strikethrough": True, "color": "#b9ecff", "text": "="},
|
||||
{"strikethrough": True, "color": "#c0eaff", "text": "="},
|
||||
{"strikethrough": True, "color": "#c7e8ff", "text": "="},
|
||||
{"strikethrough": True, "color": "#cee6ff", "text": "="},
|
||||
{"strikethrough": True, "color": "#d5e4ff", "text": "="},
|
||||
{"strikethrough": True, "color": "#dce2ff", "text": "="},
|
||||
{"strikethrough": True, "color": "#e3e0ff", "text": "="},
|
||||
{"strikethrough": True, "color": "#eadeff", "text": "="},
|
||||
{"strikethrough": True, "color": "#f1dcff", "text": "="},
|
||||
{"strikethrough": True, "color": "#f8daff", "text": "="},
|
||||
{"strikethrough": True, "color": "#ffd9ff", "text": "="},
|
||||
{"strikethrough": True, "color": "#f4dcff", "text": "="},
|
||||
{"strikethrough": True, "color": "#f9daff", "text": "="},
|
||||
{"strikethrough": True, "color": "#ffd9ff", "text": "="},
|
||||
{"color": "white", "text": " "},
|
||||
{"bold": True, "color": "#66ff99", "text": "C"},
|
||||
{"bold": True, "color": "#75f5a2", "text": "r"},
|
||||
{"bold": True, "color": "#84ebab", "text": "e"},
|
||||
{"bold": True, "color": "#93e2b4", "text": "a"},
|
||||
{"bold": True, "color": "#a3d8bd", "text": "t"},
|
||||
{"bold": True, "color": "#b2cfc6", "text": "i"},
|
||||
{"bold": True, "color": "#c1c5cf", "text": "v"},
|
||||
{"bold": True, "color": "#d1bbd8", "text": "e"},
|
||||
{"bold": True, "color": "#e0b2e1", "text": "F"},
|
||||
{"bold": True, "color": "#efa8ea", "text": "u"},
|
||||
{"bold": True, "color": "#ff9ff4", "text": "n "},
|
||||
{"strikethrough": True, "color": "#b3eeff", "text": "="},
|
||||
{"strikethrough": True, "color": "#b9ecff", "text": "="},
|
||||
{"strikethrough": True, "color": "#c0eaff", "text": "="},
|
||||
{"strikethrough": True, "color": "#c7e8ff", "text": "="},
|
||||
{"strikethrough": True, "color": "#cee6ff", "text": "="},
|
||||
{"strikethrough": True, "color": "#d5e4ff", "text": "="},
|
||||
{"strikethrough": True, "color": "#dce2ff", "text": "="},
|
||||
{"strikethrough": True, "color": "#e3e0ff", "text": "="},
|
||||
{"strikethrough": True, "color": "#eadeff", "text": "="},
|
||||
{"strikethrough": True, "color": "#f1dcff", "text": "="},
|
||||
{"strikethrough": True, "color": "#f8daff", "text": "="},
|
||||
{"strikethrough": True, "color": "#ffd9ff", "text": "="},
|
||||
{"strikethrough": True, "color": "#f4dcff", "text": "="},
|
||||
{"strikethrough": True, "color": "#f9daff", "text": "="},
|
||||
{"strikethrough": True, "color": "#ffd9ff", "text": "="},
|
||||
{"color": "white", "text": " \n "},
|
||||
{"bold": True, "color": "#E5E5E5", "text": "The server has been updated to "},
|
||||
{"bold": True, "color": "#97ABFF", "text": "1.17.1"},
|
||||
],
|
||||
"text": "",
|
||||
}
|
||||
)
|
||||
assert (
|
||||
out
|
||||
== " ===============§f §lC§lr§le§la§lt§li§lv§le§lF§lu§ln ===============§f \n §lThe server has been updated to §l1.17.1"
|
||||
)
|
||||
|
||||
def test_parse_description(self):
|
||||
out = PingResponse._parse_description("test §2description")
|
||||
assert out == "test §2description"
|
||||
|
||||
Reference in New Issue
Block a user