-
Notifications
You must be signed in to change notification settings - Fork 15
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
Inja transformation preserve escaped json #258
Conversation
api/envoy/config/filter/http/transformation/v2/transformation_filter.proto
Outdated
Show resolved
Hide resolved
Issues linked to changelog: |
// Use to render the output of a body transformation as JSON. This will cause | ||
// rendered string values to be escaped in order to make valid JSON strings | ||
bool render_body_as_json = 12; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we should rename this. perhaps this has similar utility for folks who want the body rendered for, say, yaml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
say escape_characters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it. I renamed the field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm beyond naming nit
add comments; rename new proto field; add tests for nested json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
// make sure to bail if we're not working with a raw string value | ||
if(!input->is_string()) { | ||
return input->get_ref<const std::string&>(); | ||
} | ||
|
||
auto val = input->dump(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users have the issue that when they transform a request or response body that includes escaped characters, for example this json request/response body
The characters lose their escaping when used in a template e.g. the template
{"response":"{{ foo }}"}
would produce the stringwhich is not valid JSON since the quotes are not escaped. Instead we expect to be able to produce
This PR provides 2 methods of achieving this
raw_string
can be used to escape a particular value within a template.{"response":"{{ raw_string(foo) }}"}
escape_characters
on theTransformationTemplate
setting