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

Issue with json inside json when it contains \n #2878

Open
5 tasks
donhardman opened this issue Dec 22, 2024 · 1 comment
Open
5 tasks

Issue with json inside json when it contains \n #2878

donhardman opened this issue Dec 22, 2024 · 1 comment
Assignees
Labels

Comments

@donhardman
Copy link
Contributor

Bug Description:

It seems that at some point, we changed our JSON encoding/decoding scheme, which led to different behavior. Previously, we showed \\n, but now we have \n, which causes issues with JSON-in-JSON encoding.

mysql> create table mre(field string);
mysql> insert into mre (field) values ('{"value":"Hello\nWorld"}');
mysql> select * from mre;
+---------------------+-------------------------+
| id                  | field                   |
+---------------------+-------------------------+
| 1227966080878641153 | {"value":"Hello
World"} |
+---------------------+-------------------------+
> ^C
root@dev:/workdir# curl "0:9308/sql?mode=raw" -d "select * from mre;"
[{
"columns":[{"id":{"type":"long long"}},{"field":{"type":"string"}}],
"data":[
{"id":1227966080878641153,"field":"{\"value\":\"Hello\nWorld\"}"}
],
"total":1,
"error":"",
"warning":""
}]root@dev:/workdir#

Expected:

➜  ~  php -r 'var_dump(json_encode(["field" => json_encode(["value" => "hello\nworld"])]));'
string(41) "{"field":"{\"value\":\"hello\\nworld\"}"}"

We can see that \n becomes \\n as it's properly escaped

Manticore Search Version:

Latest dev version

Operating System Version:

Ubuntu Jammy

Have you tried the latest development version?

None

Internal Checklist:

To be completed by the assignee. Check off tasks that have been completed or are not applicable.

  • Implementation completed
  • Tests developed
  • Documentation updated
  • Documentation reviewed
  • Changelog updated
@tomatolog
Copy link
Contributor

I checked your example and do not see the issue.

insert into mre (field) values ('{"value":"Hello\nWorld"}');

inserts string value and either

mysql> select * from mre;
+---------------------+-------------------------+
| id                  | field                   |
+---------------------+-------------------------+
| 1227966080878641153 | {"value":"Hello
World"} |
+---------------------+-------------------------+
root@dev:/workdir# curl "0:9308/sql?mode=raw" -d "select * from mre;"
[{
"columns":[{"id":{"type":"long long"}},{"field":{"type":"string"}}],
"data":[
{"id":1227966080878641153,"field":"{\"value\":\"Hello\nWorld\"}"}
],

returns field string attribute with the all control chars escaped as it should, ie match the original data.

Your example

php -r 'var_dump(json_encode(["field" => json_encode(["value" => "hello\nworld"])]));'

has json_encode twice - now quite sure why daemon should encode plain string second time

@tomatolog tomatolog assigned donhardman and unassigned tomatolog Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants