Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,11 @@ impl Style {
"reverse" => rv.reverse(),
"hidden" => rv.hidden(),
"strikethrough" => rv.strikethrough(),
on_true_color if on_true_color.starts_with("on_#") && on_true_color.len() == 10 => {
on_true_color
if on_true_color.starts_with("on_#")
&& on_true_color.len() == 10
&& on_true_color.is_ascii() =>
{
if let (Ok(r), Ok(g), Ok(b)) = (
u8::from_str_radix(&on_true_color[4..6], 16),
u8::from_str_radix(&on_true_color[6..8], 16),
Expand All @@ -352,7 +356,11 @@ impl Style {
continue;
}
}
true_color if true_color.starts_with('#') && true_color.len() == 7 => {
true_color
if true_color.starts_with('#')
&& true_color.len() == 7
&& true_color.is_ascii() =>
{
if let (Ok(r), Ok(g), Ok(b)) = (
u8::from_str_radix(&true_color[1..3], 16),
u8::from_str_radix(&true_color[3..5], 16),
Expand Down Expand Up @@ -1195,3 +1203,27 @@ fn test_attributes_many() {
assert_eq!(&attrs.attrs().collect::<Vec<_>>(), test_attrs);
}
}

#[test]
fn test_style_from_non_ascii_fg() {
// len() == 7, starts_with('#'), but slices [1..3] land mid-€ (3 bytes)
let fg = "#€€";
assert_eq!(fg.len(), 7);

let parsed_style = Style::from_dotted_str(fg);

// silently ignores non-ascii
assert_eq!(parsed_style, Style::default());
}

#[test]
fn test_style_from_non_ascii_bg() {
// len() == 10, starts_with("on_#"), but slices [4..6] land mid-€
let bg = "on_#€€";
assert_eq!(bg.len(), 10);

let parsed_style = Style::from_dotted_str(bg);

// silently ignores non-ascii
assert_eq!(parsed_style, Style::default());
}
Loading