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

Entity with String field containing " (quotes) in value makes frontend produce error #274

Closed
OmarHawk opened this issue Oct 9, 2024 · 1 comment · Fixed by #278
Closed

Comments

@OmarHawk
Copy link
Contributor

OmarHawk commented Oct 9, 2024

Assume we have an entity, that has a String field. The user saves a value that contains a quote character into the string field, e.g.

hello "Peter"

When trying to load the entity changes for that entity, the frontend produces an error like this and the list view does not work at all for that entity.

VM445:1 Uncaught SyntaxError: Expected ',' or '}' after property value in JSON at position 450 (line 1 column 451)
    at JSON.parse (<anonymous>)

This is because of the following:

StringBuilder sb = new StringBuilder("{");
for (String s:snapshot.getState().getPropertyNames()) {
count++;
Object propertyValue = snapshot.getPropertyValue(s);
sb.append("\"" + s + "\": \"" + propertyValue + "\"");
if (count < snapshot.getState().getPropertyNames().size()) {
sb.append(",");
}
}
sb.append("}");
entityAuditEvent.setEntityValue(sb.toString());

-> The entity propertyValue is not being escaped properly.

@OmarHawk
Copy link
Contributor Author

OmarHawk commented Oct 9, 2024

Probably other characters like line breaks could pose the same issue.

OmarHawk added a commit to OmarHawk/generator-jhipster-entity-audit that referenced this issue Oct 9, 2024
by using Jackson to produce a JSON string instead

Fixes jhipster#274
@mshima mshima closed this as completed in 3fa7432 Oct 9, 2024
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 a pull request may close this issue.

1 participant