Skip to content

Fix Postgres JSON literal escaping#740

Merged
josevalim merged 1 commit into
elixir-ecto:masterfrom
lukaszsamson:ls-fix-json-escape
Jul 3, 2026
Merged

Fix Postgres JSON literal escaping#740
josevalim merged 1 commit into
elixir-ecto:masterfrom
lukaszsamson:ls-fix-json-escape

Conversation

@lukaszsamson

Copy link
Copy Markdown
Contributor

escape_json currently only escaped SQL apostrophes and double quotes.
Postgres @> expects a valid JSON document (https://www.postgresql.org/docs/current/functions-json.html). Strings used as keys and values must be properly escaped. This means all control chars U+0000 through U+001F need to be escaped (see https://datatracker.ietf.org/doc/html/rfc8259?__cf_chl_f_tk=f0Es59csTLiHR36fEhOVvbT3bVDBL3dt925zlGXXFPo-1783109415-1.0.1.1-rqzTfCu6xNB4A47P920WmggAPsJPMBPPAjmMPE9Er00#section-7).

This PR uses a JSON lib. If a self contained approach is preferred I'll update the PR

Fixes #739

@josevalim josevalim merged commit 86ec289 into elixir-ecto:master Jul 3, 2026
8 of 10 checks passed
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

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.

Invalid escaping in JSON

2 participants