Ability to ignore unidcode decode errors.
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 9.9k
- Forks
- 2.1k
- PR merge metrics
- No merged PRs in 30d
Description
I ran on a issue today where I as trying to read a File object from a malformed utf-8 string with an invalid character. I managed to fix my issue creating my own readlines() function with a try/catch block, but I don't think this solution is resistant to future updates from this libary since I cant' guarantee that the file cursor will move to the next line before this error occur.
def readlines(file):
lines = []
eof = False
while not eof:
try:
line = file.readline()
if line == '':
eof = True
else:
lines.append(line)
except UnicodeDecodeError as e:
lines.append(e.object.decode('utf-8',errors='replace'))
return lines
One simple solution to this would be adding a default error handling in line 68.
changing to
return s.decode(encoding, errors='replace')
or even better giving the user the choice of how she/he would handle the errors via an optional argument.
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 in py3compat.py around lines 60–71, then reproduce the malformed UTF-8 File.readline case described in the issue. Review how decoding errors are currently surfaced and determine the intended replacement-versus-configurable behavior; done means the chosen handling is documented and the malformed-input behavior is covered by validation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- networking
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100