Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug fmt handles unicode boundaries #254

Merged
merged 3 commits into from
Jul 4, 2024

Conversation

adwhit
Copy link
Contributor

@adwhit adwhit commented Jul 4, 2024

I realised that #253 can introduce a panic when handling non-ascii unicode character (see e.g. https://old.reddit.com/r/rust/comments/765n76/psa_caution_with_slicing_strings/). Here is the fix.

Also bumped the pnpm action to v4, as suggested in pnpm/pnpm#6424.

Copy link
Member

@charypar charypar left a comment

Choose a reason for hiding this comment

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

Oops, probably should've caught that in the last review 😓

@charypar charypar merged commit 8c6e9b4 into redbadger:master Jul 4, 2024
9 checks passed
@adwhit adwhit deleted the fix-better-http branch July 4, 2024 09:43
if s.len() < 50 {
format!("\"{s}\"")
} else {
format!("\"{}\"...", &s[..50])
format!("\"{}\"...", s.chars().take(50).collect::<String>())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be nice to avoid allocating a string only to write it straight into another string and drop it again.

let (index, _) = s.char_indices().nth(50);
format!("\"{}\"...", &s[..index])

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.

3 participants