Skip to content

Max length in strip_string() should by bytes not characters. #1691

@antonpirker

Description

@antonpirker

How do you use Sentry?

Sentry Saas (sentry.io)

Version

1.9.10

Steps to Reproduce

If you use this function:
https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/utils.py#L834-L854

If you use a value that contains unicode characters like this one:
Randolph Carter est obsédé par la redécouverte de la ville du coucher, la ville de ses rêves.

Expected Result

The truncation and indexes in the AnnotatedValue should be done by number of bytes and not number of characters.

Actual Result

The index range in the resulting AnnotatedValue is wrong, because it is the len() in characters and not the len in bytes.

To use the byte length one has to use something like this:

length = len(value.encode("utf-8"))

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions