Replace String.to_integer with safe Integer.parse

Use Integer.parse/1 instead of String.to_integer/1 on user-supplied
and external API input to prevent ArgumentError crashes on non-numeric
values. Adds fallback defaults or nil returns at each call site.
This commit is contained in:
Claudio Ortolina
2026-03-05 14:27:37 +00:00
parent 23c478fe4c
commit eb8a00ab54
6 changed files with 39 additions and 19 deletions
+4 -2
View File
@@ -73,8 +73,10 @@ defmodule LastFm.Track do
end
defp parse_scrobble_at_uts(track) do
track["date"]["uts"]
|> String.to_integer()
case Integer.parse(track["date"]["uts"]) do
{int, ""} -> int
_ -> nil
end
end
def changeset(track, attrs) do