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
+7 -1
View File
@@ -53,7 +53,13 @@ defmodule MusicBrainz.Artist do
end)
end
defp parse_discogs_id("https://www.discogs.com/artist/" <> id), do: String.to_integer(id)
defp parse_discogs_id("https://www.discogs.com/artist/" <> id) do
case Integer.parse(id) do
{int, ""} -> int
_ -> nil
end
end
defp parse_discogs_id(_other), do: nil
defp parse_wikidata_id("https://www.wikidata.org/wiki/" <> id), do: id