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

djc merged 2 commits into
console-rs:mainfrom
danjl1100:style-ignore-nonascii

Conversation

@danjl1100

@danjl1100 danjl1100 commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

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

danjl1100 commented May 11, 2026 •

Copy link
Copy Markdown
Contributor Author

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

@djc

djc commented May 12, 2026

Copy link
Copy Markdown
Member

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

Pre-existing, should be fixed if you rebase:

@djc djc left a comment

Copy link
Copy Markdown
Member

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
kodiakhq Bot pushed a commit to pdylanross/fatigue that referenced this pull request Jul 2, 2026
Bumps console from 0.16.3 to 0.16.4.

Release notes
Sourced from console's releases.

0.16.4
What's Changed

chore: Remove redudant helper and add TermInner constructors by @​ChrisDenton in console-rs/console#284
Style::from_dotted_str ignore non-ascii by @​danjl1100 in console-rs/console#287
feat: add is_dumb public function by @​ugur-eren in console-rs/console#290




Commits

598eca9 Bump version to 0.16.4
0f22c35 feat: add is_dumb public function
1426649 Bump actions/checkout from 3 to 7
d2d89ad ignore non-ascii input in Style::from_dotted_str
6cff3e0 document current panic in Style::from_dotted_str via test cases
dd4334f Apply suggestions from clippy 1.95
586efad Remove redundant as_handle helper
be20e85 Add TermInner::new constructors
See full diff in compare view




Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options

You can trigger Dependabot actions by commenting on this PR:

@dependabot rebase will rebase this PR
@dependabot recreate will recreate this PR, overwriting any edits that have been made to it
@dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency
@dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
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