Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle improper lists in RedactorEncoder #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

martosaur
Copy link

@martosaur martosaur commented Mar 15, 2025

Hi 👋

Currently, RedactorEncoder can't handle an improper list and would crash a formatter:

iex(1)> LoggerJSON.Formatter.RedactorEncoder.encode([1 | 2], [])
** (FunctionClauseError) no function clause matching in Enum."-map/2-lists^map/1-1-"/2

    The following arguments were given to Enum."-map/2-lists^map/1-1-"/2:

        # 1
        #Function<3.49609762/1 in LoggerJSON.Formatter.RedactorEncoder.encode/2>

        # 2
        2

    (elixir 1.18.2) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
    (elixir 1.18.2) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
    iex:1: (file)

This PR attempts to fix it. There are probably multiple ways this can be addressed, but I went with inspecting the list after all individual elements were encoded. This way it'll be visible that something isn't right and no data will go unredacted.

Oh, and my personal real world example where the redactor was crashing is when I tried to log Plug.Conn.resp_body, which is of iodata type and is often an improper list.

Let me know what you think!

@kpan2025
Copy link

I'm also got this issue, hope to fix it soon, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants