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

API: Fix out of bound error on empty playlists #4696

Merged
merged 1 commit into from
Jul 21, 2024

Conversation

Fijxu
Copy link
Contributor

@Fijxu Fijxu commented May 14, 2024

Invidious assumes that every playlist will have at least one video because it needs to check for the index key. So if there is no videos on a playlist, there is no index key and Invidious throws Index out of bounds

This fixes this API endpoints when there is no videos in a playlist:

api/v1/playlists/:plid
api/v1/auth/playlists/:plid

For some weird reason, the api/v1/auth/playlists/:plid endpoint was able the return the error Index out of bounds as said in #4679 but api/v1/playlists/:plid did not return anything. Weird

Fixes #4679

Invidious assumes that every playlist will have at least one video
because it needs to check for the `index` key. So if there is no videos
on a playlist, there is no `index` key and Invidious throws
`Index out of bounds`
@Fijxu Fijxu requested a review from a team as a code owner May 14, 2024 01:20
@Fijxu Fijxu requested review from syeopite and removed request for a team May 14, 2024 01:20
@Fijxu
Copy link
Contributor Author

Fijxu commented May 14, 2024

Can be tested with a empty playlist that I created at https://debuginv.nadeko.net/api/v1/playlists/PL5ASK6Z87scO0GrGbMzxVz5qvMhRUitbG

@SamantazFox SamantazFox added the need-testing This feature needs to be deployed and tested to see if it's working, and doesn't break something label May 20, 2024
@SamantazFox SamantazFox added in-testing This feature has been deployed and is being tested ready and removed need-testing This feature needs to be deployed and tested to see if it's working, and doesn't break something in-testing This feature has been deployed and is being tested labels Jul 17, 2024
@SamantazFox
Copy link
Member

For some weird reason, the api/v1/auth/playlists/:plid endpoint was able the return the error Index out of bounds as said in #4679 but api/v1/playlists/:plid did not return anything. Weird

This because the authentication middleware (AuthHandler) catches the error and displays it nicely:

rescue ex
env.response.content_type = "application/json"
error_message = {"error" => ex.message}.to_json
env.response.status_code = 403
env.response.print error_message
end

@SamantazFox SamantazFox changed the title API: Check if playlist has any videos on it. API: Fix out of bound error on empty playlists Jul 21, 2024
@SamantazFox SamantazFox merged commit 4f60fee into iv-org:master Jul 21, 2024
6 of 7 checks passed
@SamantazFox
Copy link
Member

Thank you for fixing this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] API returns 403 with error "index out of bound" when calling a playlist with 0 videos
2 participants