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

fix: allow usage of double quotes within json bodies #38

Merged
merged 1 commit into from Aug 3, 2021

Conversation

darora
Copy link
Contributor

@darora darora commented Aug 3, 2021

A valid json object that includes a double quote escaped within a string causes an error.

Not sure if this is the best way to fix this!

postgres=# select json_build_object('foo', 'b"ar')::text;
 json_build_object
-------------------
 {"foo" : "b\"ar"}
(1 row)

postgres=# select json_build_object('foo', 'b"ar')::text::bytea;
ERROR:  invalid input syntax for type bytea

postgres=# select convert_to(json_build_object('foo', 'b"ar')::text, 'UTF8');
              convert_to
--------------------------------------
 \x7b22666f6f22203a2022625c226172227d
(1 row)

@soedirgo
Copy link
Member

soedirgo commented Aug 3, 2021

Thanks @darora! The problem is text::bytea is expecting escape format for textual repr of bytea. You can only escape either a backslash or an octet, so \" is invalid (and the fix is correct - should have used convert_to).

LGTM! Waiting for the others to chime in.

@soedirgo soedirgo merged commit 9d3fdcd into master Aug 3, 2021
@soedirgo soedirgo deleted the da/allow-use-of-double-quotes branch August 3, 2021 14:45
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.

None yet

3 participants