From cda7d7a24694cd469f44f5f847726893402d3587 Mon Sep 17 00:00:00 2001 From: Billal Ghilas <84322223+gBillal@users.noreply.github.com> Date: Mon, 23 Dec 2024 12:04:06 +0100 Subject: [PATCH] Do not crash on invalid line type (#53) --- lib/ex_sdp/parser.ex | 2 ++ test/sdp_test.exs | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/ex_sdp/parser.ex b/lib/ex_sdp/parser.ex index e07808c..1600972 100644 --- a/lib/ex_sdp/parser.ex +++ b/lib/ex_sdp/parser.ex @@ -146,6 +146,8 @@ defmodule ExSDP.Parser do end end + defp parse_line(_lines, _session), do: {:error, :invalid_line} + defp format_error(["m=" <> _rest = line | rest], reason) do attributes = rest diff --git a/test/sdp_test.exs b/test/sdp_test.exs index 49ac500..3e3e915 100644 --- a/test/sdp_test.exs +++ b/test/sdp_test.exs @@ -143,6 +143,19 @@ defmodule ExSDPTest do assert {:error, {:invalid_bandwidth, "b=X-YZ:256"}} == assert(ExSDP.parse(input)) end + + test "returns an error on invalid line" do + input = + """ + v=0 + o=jdoe 2890844526 2890842807 IN IP4 10.47.16.5 + l=invalid line + s=Very fancy session name + """ + |> String.replace("\n", "\r\n") + + assert {:error, {:invalid_line, "l=invalid line"}} = ExSDP.parse(input) + end end describe "Parser parse!/1" do