decodeCWithCharset error handling inconsistency
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 2.5k
- Forks
- 636
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 7
Description
utf8.decodeC is a specialization of the generic private decoder used for other charsets:
def decodeCWithCharset[F[_]: RaiseThrowable](charset: Charset): Pipe[F, Chunk[Byte], String] =
if (charset.name() == StandardCharsets.UTF_8.name())
utf8.decodeC
else
decodeCWithGenericCharset(charset)
On bad input, the UTF8 decoder succeeds with the Unicode replacement character, and the other charsets raise an error:
scala> Stream(0xc0, 0xaf).map(_.toByte).covary[Fallible].chunks.through(text.utf8.decodeC).compile.string
val res14: scala.util.Either[Throwable,String] = Right(��)
scala> Stream(0xc0, 0xaf).map(_.toByte).covary[Fallible].chunks.through(text.decodeCWithGenericCharset(UTF_8)).compile.string
val res15: scala.util.Either[Throwable,String] = Left(java.nio.charset.MalformedInputException: Input length = 1)
There's no visible UTF-8 encoder that raises errors, nor is there an generic encoder that uses replacement characters. We might want to make the behavior configurable, but it should at least be consistent.
Contributor guide
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 comparing the utf8.decodeC path in decodeCWithCharset with decodeCWithGenericCharset, using the malformed UTF-8 examples in the issue. Determine the intended configurable error behavior, then ensure the UTF-8 and generic charset decoders handle invalid input consistently and add coverage for both paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- stream-processing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100