Skip to content

Commit

Permalink
Playlists: Fix 'invalid byte sequence' error when subscribing (#4887)
Browse files Browse the repository at this point in the history
In Crystal, handling multi-byte sequences in UTF-8 requires understanding that
slicing by bytes can lead to invalid sequences if the slicing isn't aligned
with character boundaries. In this case, attempting to slice a string by bytes
can cut through multi-byte UTF-8 sequences, leading to invalid sequences.

To avoid this, strings should be sliced based on characters rather than bytes.

Fixes issue 4886
  • Loading branch information
SamantazFox committed Oct 8, 2024
2 parents 0ac9367 + bd34659 commit 97895a4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/invidious/playlists.cr
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ end

def subscribe_playlist(user, playlist)
playlist = InvidiousPlaylist.new({
title: playlist.title.byte_slice(0, 150),
title: playlist.title[..150],
id: playlist.id,
author: user.email,
description: "", # Max 5000 characters
Expand Down

0 comments on commit 97895a4

Please sign in to comment.