[PR #251] [MERGED] Allow negative values in duration_ms #342

Closed
opened 2026-02-27 20:24:20 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ramsayleung/rspotify/pull/251
Author: @flip1995
Created: 9/15/2021
Status: Merged
Merged: 9/15/2021
Merged by: @ramsayleung

Base: masterHead: neg_resume_position_ms


📝 Commits (1)

  • d654f82 Allow negative values in duration_ms

📊 Changes

2 files changed (+19 additions, -0 deletions)

View changed files

📝 rspotify-model/src/custom_serde.rs (+6 -0)
📝 tests/test_models.rs (+13 -0)

📄 Description

Description

This patch adds a parser for i64 values to duration_ms, so that it no longer fails for negative numbers. This works, according to the serde documentation:

The JSON Deserializer will call visit_i64 for any signed integer and visit_u64 for any unsigned integer, even if hinted a different type.

Motivation and Context

The spotify API doesn't make any guarantees, if the returned integers are signed or unsigned. It turns out, that for the resume_position_ms value in the ResumePointObject used for Episodes can be negative. I've only seen the value -1000, but don't know when this occurs or if other values are possible.

I noticed this using the spotify-tui crate, that uses this crate as a dependency. See screenshot below:
image

Dependencies

None

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

By adding a unit test to the test_models file. The previous behavior is unchanged (according to existing tests)


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ramsayleung/rspotify/pull/251 **Author:** [@flip1995](https://github.com/flip1995) **Created:** 9/15/2021 **Status:** ✅ Merged **Merged:** 9/15/2021 **Merged by:** [@ramsayleung](https://github.com/ramsayleung) **Base:** `master` ← **Head:** `neg_resume_position_ms` --- ### 📝 Commits (1) - [`d654f82`](https://github.com/ramsayleung/rspotify/commit/d654f82475297399632c6fd5625c572dd20eb024) Allow negative values in duration_ms ### 📊 Changes **2 files changed** (+19 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `rspotify-model/src/custom_serde.rs` (+6 -0) 📝 `tests/test_models.rs` (+13 -0) </details> ### 📄 Description ## Description This patch adds a parser for `i64` values to `duration_ms`, so that it no longer fails for negative numbers. This works, according to the [serde documentation](https://serde.rs/impl-deserialize.html#driving-a-visitor): > The JSON `Deserializer` will call `visit_i64` for any signed integer and `visit_u64` for any unsigned integer, even if hinted a different type. ## Motivation and Context The spotify API doesn't make any guarantees, if the returned integers are signed or unsigned. It turns out, that for the `resume_position_ms` value in the `ResumePointObject` used for `Episode`s can be negative. I've only seen the value `-1000`, but don't know when this occurs or if other values are possible. I noticed this using the `spotify-tui` crate, that uses this crate as a dependency. See screenshot below: ![image](https://user-images.githubusercontent.com/9744647/133422112-4d862772-14e7-4372-a95c-a185d314300a.png) ## Dependencies None ## Type of change Please delete options that are not relevant. - [x] Bug fix (non-breaking change which fixes an issue) ## How Has This Been Tested? By adding a unit test to the `test_models` file. The previous behavior is unchanged (according to existing tests) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 20:24:20 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/rspotify#342
No description provided.