Skip to content

Style::from_dotted_str ignore non-ascii#287

Merged
djc merged 2 commits into
console-rs:mainfrom
danjl1100:style-ignore-nonascii
May 12, 2026
Merged

Style::from_dotted_str ignore non-ascii#287
djc merged 2 commits into
console-rs:mainfrom
danjl1100:style-ignore-nonascii

Conversation

@danjl1100
Copy link
Copy Markdown
Contributor

@danjl1100 danjl1100 commented May 11, 2026

True colors were added to Style::from_dotted_str in v0.16.2, but it seems like the string slicing only works for ascii (panicking for certain inputs).

Of course, only ascii is expected as an input to the function, but I figured I'd raise this PR since the doc for that function ends with "Unknown terms are ignored". It seems unlikely (possible?) that someone would provide user-input to this function. At least the length check ensures we're not linearly checking ascii in any huge strings.

  • The first commit demonstrates the panic in the current code with #[expect_panic] tests.
  • The second commit checks for ascii in the offending branches and removes #[expect_panic] to verify "Unknown terms are ignored".

I identified this improvement while reviewing a delta in cargo-vet (myself).

I used AI to create the input strings that trigger both panic branches (as it's more familiar with UTF-8 details than me), but the commits and asserts are my own. I debated removing the comments the AI generated above the two inputs, but it seems like it helps document (at least against the current implementation). Feel free to adjust as you see fit.

@danjl1100
Copy link
Copy Markdown
Contributor Author

danjl1100 commented May 11, 2026

Hm.. I'm not sure why the lint run on windows failed (the others passed)

@djc
Copy link
Copy Markdown
Member

djc commented May 12, 2026

Hm.. I'm not sure why the lint run on windows failed (the others passed)

Pre-existing, should be fixed if you rebase:

Copy link
Copy Markdown
Member

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks!

@danjl1100 danjl1100 force-pushed the style-ignore-nonascii branch from d9b0786 to 0ebc85f Compare May 12, 2026 16:25
@danjl1100
Copy link
Copy Markdown
Contributor Author

Awesome, rebased and the checks look better now.

@djc djc merged commit d2d89ad into console-rs:main May 12, 2026
20 checks passed
@danjl1100 danjl1100 deleted the style-ignore-nonascii branch May 12, 2026 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants