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

MetricsAsJson produces incorrect JSON (=does not quote special characters) #3209

Closed
rPraml opened this issue Aug 30, 2023 · 1 comment · Fixed by #3228
Closed

MetricsAsJson produces incorrect JSON (=does not quote special characters) #3209

rPraml opened this issue Aug 30, 2023 · 1 comment · Fixed by #3228
Assignees
Labels
Milestone

Comments

@rPraml
Copy link
Contributor

rPraml commented Aug 30, 2023

Expected behavior

When collecting metrics with collectMetrics().asJson() I expect that a valid json is returned

Actual behavior

We have a raw query:

setRaw("json_field = replace(json_field , '\"type\":\"Foo\"', '\"type\":\"Bar\"')").update()

in our application. The query itself is irrelevant, only the fact, that it contains " is important here

Steps to reproduce

The SQL is appended without quoting here
https://github.com/ebean-orm/ebean/blob/master/ebean-api/src/main/java/io/ebean/meta/MetricsAsJson.java#L149
and results in a metric json that looks like this

   "sql" : "update table set json_field = replace(json_field , '"type":"Foo"', '"type":"Bar"')"

which is invalid.

We need some quoting and I'm thinking about what would be the easiest or most efficient way.

  • do a bunch of replaces (str.replace("\\", "\\\\").replace("\"", "\\\"").replace("\b", "\\b").replace("\f", "\\f").replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t");)
  • delegate to a Json-libary
  • port Escape.java from avaje-jsonb or similar
@rbygrave rbygrave self-assigned this Oct 4, 2023
@rbygrave rbygrave added the bug label Oct 4, 2023
@rbygrave rbygrave linked a pull request Oct 4, 2023 that will close this issue
rbygrave added a commit that referenced this issue Oct 4, 2023
#3209 MetricsAsJson escape the SQL string content
@rbygrave rbygrave added this to the 13.22.1 milestone Oct 4, 2023
@rbygrave
Copy link
Member

rbygrave commented Oct 4, 2023

We can go with using string replace for now. This can be replaced with avaje-jsonb later on.

nPraml pushed a commit to FOCONIS/ebean that referenced this issue Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants