Skip to content

Commit

Permalink
Fix handling of Content-Types with multiple params (#87)
Browse files Browse the repository at this point in the history
Microsoft's Azure AD v2.0 token endpoint responds with a Content-Type
containing multiple parameters, but the previous code only processes
cases with a content type, with or without a single parameter.
  • Loading branch information
simonalpha authored and scrogson committed Jan 25, 2017
1 parent a8f5926 commit 7970ce6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/oauth2/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ defmodule OAuth2.Util do
end

defp remove_params(binary) do
case String.split(binary, ";") do
[content_type, _] -> content_type
[content_type] -> content_type
end
[content_type | _] = String.split(binary, ";")
content_type
end

defp parse_content_type(content_type) do
Expand Down
1 change: 1 addition & 0 deletions test/oauth2/util_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule OAuth2.UtilTest do
assert "application/json" == Util.content_type([])
assert "application/vnd.api+json" == Util.content_type([{"content-type", "application/vnd.api+json"}])
assert "application/xml" == Util.content_type([{"content-type", "application/xml; version=1.0"}])
assert "application/json" == Util.content_type([{"content-type", "application/json;param;param"}])

assert_raise OAuth2.Error, fn ->
Util.content_type([{"content-type", "trash; trash"}])
Expand Down

0 comments on commit 7970ce6

Please sign in to comment.