From 585f46fe49406f25ebb2ed355714abb8d141fa28 Mon Sep 17 00:00:00 2001 From: Jakub Pisarek <99591440+sgfn@users.noreply.github.com> Date: Thu, 19 Sep 2024 18:00:02 +0200 Subject: [PATCH 1/2] Fix parsing integer framerate --- lib/ex_sdp/attribute.ex | 29 +++++++++++++++++++++++++---- test/ex_sdp/attribute_test.exs | 4 ++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/lib/ex_sdp/attribute.ex b/lib/ex_sdp/attribute.ex index e203fb6..f487f2f 100644 --- a/lib/ex_sdp/attribute.ex +++ b/lib/ex_sdp/attribute.ex @@ -171,13 +171,34 @@ defmodule ExSDP.Attribute do end defp parse_framerate(framerate) do - case String.split(framerate, "/") do - [value] -> {:ok, {:framerate, String.to_float(value)}} - [left, right] -> {:ok, {:framerate, {String.to_integer(left), String.to_integer(right)}}} - _invalid_framerate -> {:error, :invalid_framerate} + framerate + |> String.split("/") + |> parse_split_framerate() + |> case do + {:ok, framerate} -> {:ok, {:framerate, framerate}} + :error -> {:error, :invalid_framerate} end end + defp parse_split_framerate([value]) do + with {number, ""} <- Float.parse(value) do + {:ok, number} + else + _other -> :error + end + end + + defp parse_split_framerate([left, right]) do + with {num, ""} <- Integer.parse(left), + {denom, ""} <- Integer.parse(right) do + {:ok, {num, denom}} + else + _other -> :error + end + end + + defp parse_split_framerate(_invalid_framerate), do: :error + defp parse_fingerprint(fingerprint) do case String.split(fingerprint, " ") do ["sha-1", value] -> {:ok, {:fingerprint, {:sha1, value}}} diff --git a/test/ex_sdp/attribute_test.exs b/test/ex_sdp/attribute_test.exs index d7a9bb8..7e3758c 100644 --- a/test/ex_sdp/attribute_test.exs +++ b/test/ex_sdp/attribute_test.exs @@ -6,6 +6,10 @@ defmodule ExSDP.AttributeTest do describe "Attribute parser" do test "handles framerate" do assert {:ok, {:framerate, {30, 1}}} = Attribute.parse("framerate:30/1") + assert {:ok, {:framerate, 30.0}} = Attribute.parse("framerate:30") + assert {:ok, {:framerate, 30.0}} = Attribute.parse("framerate:30.0") + assert {:error, :invalid_framerate} = Attribute.parse("framerate:foobar") + assert {:error, :invalid_framerate} = Attribute.parse("framerate:30abc") end test "handles directly assignable attributes" do From c1cb062ae0cdcbecc616543d670693cce0d80b93 Mon Sep 17 00:00:00 2001 From: Jakub Pisarek <99591440+sgfn@users.noreply.github.com> Date: Thu, 19 Sep 2024 18:18:18 +0200 Subject: [PATCH 2/2] Bump deps, release 1.0.1 --- mix.exs | 2 +- mix.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mix.exs b/mix.exs index 57e8d63..e92ef1b 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule ExSDP.MixProject do use Mix.Project - @version "1.0.0" + @version "1.0.1" @github_url "https://github.com/membraneframework/ex_sdp" def project do diff --git a/mix.lock b/mix.lock index e8537d8..4e108e1 100644 --- a/mix.lock +++ b/mix.lock @@ -7,11 +7,11 @@ "elixir_uuid": {:hex, :elixir_uuid, "1.2.1", "dce506597acb7e6b0daeaff52ff6a9043f5919a4c3315abb4143f0b00378c097", [:mix], [], "hexpm", "f7eba2ea6c3555cea09706492716b0d87397b88946e6380898c2889d68585752"}, "erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"}, "ex_doc": {:hex, :ex_doc, "0.34.2", "13eedf3844ccdce25cfd837b99bea9ad92c4e511233199440488d217c92571e8", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "5ce5f16b41208a50106afed3de6a2ed34f4acfd65715b82a0b84b49d995f95c1"}, - "file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"}, - "jason": {:hex, :jason, "1.4.3", "d3f984eeb96fe53b85d20e0b049f03e57d075b5acda3ac8d465c969a2536c17b", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "9a90e868927f7c777689baa16d86f4d0e086d968db5c05d917ccff6d443e58a3"}, + "file_system": {:hex, :file_system, "1.0.1", "79e8ceaddb0416f8b8cd02a0127bdbababe7bf4a23d2a395b983c1f8b3f73edd", [:mix], [], "hexpm", "4414d1f38863ddf9120720cd976fce5bdde8e91d8283353f0e31850fa89feb9e"}, + "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, "makeup": {:hex, :makeup, "1.1.2", "9ba8837913bdf757787e71c1581c21f9d2455f4dd04cfca785c70bbfff1a76a3", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cce1566b81fbcbd21eca8ffe808f33b221f9eee2cbc7a1706fc3da9ff18e6cac"}, "makeup_elixir": {:hex, :makeup_elixir, "0.16.2", "627e84b8e8bf22e60a2579dad15067c755531fea049ae26ef1020cad58fe9578", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "41193978704763f6bbe6cc2758b84909e62984c7752b3784bd3c218bb341706b"}, - "makeup_erlang": {:hex, :makeup_erlang, "1.0.0", "6f0eff9c9c489f26b69b61440bf1b238d95badae49adac77973cbacae87e3c2e", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "ea7a9307de9d1548d2a72d299058d1fd2339e3d398560a0e46c27dab4891e4d2"}, + "makeup_erlang": {:hex, :makeup_erlang, "1.0.1", "c7f58c120b2b5aa5fd80d540a89fdf866ed42f1f3994e4fe189abebeab610839", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "8a89a1eeccc2d798d6ea15496a6e4870b75e014d1af514b1b71fa33134f57814"}, "mix_test_watch": {:hex, :mix_test_watch, "1.2.0", "1f9acd9e1104f62f280e30fc2243ae5e6d8ddc2f7f4dc9bceb454b9a41c82b42", [:mix], [{:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm", "278dc955c20b3fb9a3168b5c2493c2e5cffad133548d307e0a50c7f2cfbf34f6"}, "nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"}, }