Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed string truncation for TestReport's comment #314

Merged
merged 1 commit into from
Jan 10, 2024
Merged

Fixed string truncation for TestReport's comment #314

merged 1 commit into from
Jan 10, 2024

Conversation

metenn
Copy link
Contributor

@metenn metenn commented Jan 6, 2024

Django's Truncator(text).chars(n) seems to ignore all unicode combining characters, resulting in incorrect string truncations.
For example,

string = 'After\u20e1 trunc, this should be 20 characters...'
temp = Truncator(string).chars(20)
print(len(temp))

this outputs:

21

If we were to remove the unicode symbol, it would correctly output 20. Whether this is truly intended or not eludes me.

When trying to put a string truncated in such manner into a CharField, it fails to pass the MaxLengthValidator check, as it internally uses len() for its check.

Since Python 3, strings respect Unicode by default, so slices seem to work fine for truncation.

@metenn metenn requested a review from twalen as a code owner January 6, 2024 22:06
@MasloMaslane
Copy link
Member

This change was tested on sio2.mimuw and works

@twalen twalen merged commit f901567 into sio2project:master Jan 10, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants