HeaderValue::to_str returns an error for valid unicode strings
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.4k
- Forks
- 378
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 5
Description
HeaderValue::to_str() returns an error if the header value contains any byte that's not "visible ASCII" (though this is misleading as \t is legal even though it's not visible). This is weird, it should just return a string if it contains a valid string regardless of the contents. We already know it doesn't contain illegal bytes (as that's checked upon creation of HeaderValue) so we don't need to check again, and there's no reason to disallow unicode characters when getting the string representation.
I think the right thing here is to just replace the implementation with std::str::from_utf8(), and replace ToStrError with a pub use std::str::Utf8Error as ToStrError for backwards compatibility.
Also see #519.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating HeaderValue::to_str and the ToStrError definition, then inspect the existing tests for header-value string conversion. Confirm how HeaderValue creation validates bytes before changing the conversion behavior. Done means valid UTF-8, including Unicode and tabs, is returned while invalid UTF-8 still errors and the ToStrError name remains compatible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- api, networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100