Skip to content

[BUG] decoding bytes error #2391

Closed

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

Activity

  1. coolreader18 commented on Jan 3, 2021

    @coolreader18
    Member

    Yeah, we don't support surrogateescape at the moment on account of using utf8 strings internally; we should probably mention that somewhere in the README or something.

  2. verhovsky commented on Jan 24, 2021

    @verhovsky
    Contributor

    See #935

  3. arihant2math commented on Feb 23, 2025

    @arihant2math
    Contributor

    No longer applicable, this can be closed.

  4. youknowone commented on Feb 23, 2025

    @youknowone
    Member

    To close this issue, I'd like to add the reported case under extra_tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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