Skip to content

Commit

Permalink
Guard against infinite values for upload task
Browse files Browse the repository at this point in the history
  • Loading branch information
GianniCarlo committed Aug 5, 2024
1 parent 52a5be9 commit e93f817
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Shared/Realm/Realm+BookPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,22 @@ import RealmSwift
extension Object {
func toDictionaryPayload() -> [String: Any] {
return objectSchema.properties.reduce(into: [:]) { dict, property in
dict[property.name] = self.value(forKeyPath: property.name)
var value = self.value(forKeyPath: property.name)

/// Sanitize infinite values
if let doubleValue = value as? Double,
!doubleValue.isFinite {
switch property.name {
case "speed", "lastPlayDateTimestamp":
value = nil
case "currentTime", "duration", "percentCompleted":
value = 0.0
default:
break
}
}

dict[property.name] = value
}
}
}

0 comments on commit e93f817

Please sign in to comment.