fix: Preview payload when correlating numeric properties#671
Conversation
There was a problem hiding this comment.
Pull Request Overview
The PR addresses an issue where payload preview fails when a numeric value is replaced by a correlation variable by wrapping variable expressions in quotes before JSON parsing.
- Updated parseParams to wrap content with variable expressions in quotes before parsing
- Added a new function (wrapTemplateExpressionsInQuotes) to handle the string transformation
Comments suppressed due to low confidence (2)
src/components/WebLogView/RequestDetails/utils.ts:74
- Consider adding unit tests for the wrapTemplateExpressionsInQuotes function to validate the regex against various edge cases.
function wrapTemplateExpressionsInQuotes(str: string) {
src/components/WebLogView/RequestDetails/utils.ts:40
- Wrapping variable expressions in quotes may lead to type inconsistencies, especially if numeric types are expected downstream. Verify the transformation with comprehensive tests to ensure that all intended cases are handled correctly.
parsePythonByteString(wrapTemplateExpressionsInQuotes(contentDecoded))
going-confetti
left a comment
There was a problem hiding this comment.
Works as expected and remedies the issue 👍
that's not ideal because it makes it look like the value injected would be a string, but at least it doesn't break the preview. We might want to revisit this in the future and remove JSON parse altogether, but we'd need a new way to prettify it.
I agree, it looks pretty confusing. I think we should remove JSON parse in future. Could you please create an issue for that?
Description
Payload preview doesn't work when a numeric value is replaced by a correlation variable, for example:
{ "id": ${correlation_vars['correlation_0'] }In Payload preview, we parse the string as JSON, but the injected variable makes in invalid.
To solve this I've added a function to wrap variable expressions in quotes, that's not ideal because it makes it look like the value injected would be a string, but at least it doesn't break the preview. We might want to revisit this in the future and remove JSON parse altogether, but we'd need a new way to prettify it.
How to Test
Use attached recording and generator.
Steps to reproduce:
POST /api/ratingsrequestExpected result: payload preview with injected correlation value is displayed
Actual result: payload preview is not available
Verify payload preview works as expected in recording, generator and validator
correlate-pizza-id.zip
Checklist
npm run lint) and all checks pass.npm test) and all tests pass.Screenshots (if appropriate):
Related PR(s)/Issue(s)