Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ sudo: false
elixir:
- 1.8
- 1.9
- '1.10'
otp_release:
- 21.2
- 22.0
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Fixed
- Safely sanitize invalid binaries when encoding JSON for notices.
- Fixes for Elixir 1.10 release (#259)

## [v0.13.0] - 2019-10-02
### Added
Expand Down
2 changes: 1 addition & 1 deletion lib/honeybadger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ defmodule Honeybadger do
@spec context(map() | keyword()) :: map()
def context(map) when is_map(map), do: context(Keyword.new(map))

def context(keyword) do
def context(keyword) when is_list(keyword) do
Logger.metadata(keyword)

context()
Expand Down
3 changes: 2 additions & 1 deletion lib/honeybadger/json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ defmodule Honeybadger.JSON do
|> to_encodeable
end

defp to_encodeable(input) when is_pid(input) or is_port(input) or is_reference(input) do
defp to_encodeable(input)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have an example of this (any of these, really) in the json tests directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test covering this to_encodable function

when is_pid(input) or is_port(input) or is_reference(input) or is_function(input) do
inspect(input)
end

Expand Down
13 changes: 13 additions & 0 deletions test/honeybadger/json_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ defmodule Honeybadger.JSONTest do
assert custom_encoded == jason_encoded
end

test "handles values requring inspection" do
{:ok, ~s("&Honeybadger.JSON.encode/1")} = JSON.encode(&Honeybadger.JSON.encode/1)
{:ok, ~s("#PID<0.250.0>")} = JSON.encode(:c.pid(0, 250, 0))

ref = make_ref()
{:ok, encoded_ref} = JSON.encode(ref)
assert "\"#{inspect(ref)}\"" == encoded_ref

port = Port.open({:spawn, "false"}, [:binary])
{:ok, encoded_port} = JSON.encode(port)
assert "\"#{inspect(port)}\"" == encoded_port
end

test "safely handling binaries with invalid bytes" do
{:ok, ~s("honeybadger")} = JSON.encode(<<"honeybadger", 241>>)
{:ok, ~s("honeybadger")} = JSON.encode(<<"honeybadger", 241, "yo">>)
Expand Down