Skip to content

[BUG] decoding bytes error #2391

Open
Open
@darleybarreto

Description

@darleybarreto

When running

b'-\xff'.decode(sys.getfilesystemencoding(), 'surrogateescape')

On both PyPy and CPython, I get

'-\udcff'

In RustPython

Traceback (most recent call last):
  File "/RustPython/vm/pylib-crate/Lib/_codecs.py", line 567, in lookup_error
    err_handler = codec_error_registry[errors]
KeyError: surrogateescape

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/RustPython/vm/pylib-crate/Lib/_codecs.py", line 140, in decode
    res = codec[1](obj, errors)
  File "/RustPython/vm/pylib-crate/Lib/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
  File "/RustPython/vm/pylib-crate/Lib/_codecs.py", line 463, in __call__
    return self._f(*args, **kwargs)
  File "/RustPython/vm/pylib-crate/Lib/_codecs.py", line 177, in utf_8_decode
    res, consumed = PyUnicode_DecodeUTF8Stateful(data, len(data), errors, final)
  File "/RustPython/vm/pylib-crate/Lib/_codecs.py", line 1133, in PyUnicode_DecodeUTF8Stateful
    s,  startinpos, endinpos)
  File "/RustPython/vm/pylib-crate/Lib/_codecs.py", line 1059, in unicode_call_errorhandler
    errorHandler = lookup_error(errors)
  File "/RustPython/vm/pylib-crate/Lib/_codecs.py", line 569, in lookup_error
    raise LookupError("unknown error handler name %s"%errors)
LookupError: unknown error handler name surrogateescape

I found this when I tried to use os_helper.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions