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

Variables in raw JSON body strings should be escaped #11049

Closed
1 task done
francisbooth opened this issue Jun 29, 2022 · 2 comments · Fixed by postmanlabs/postman-code-generators#674
Closed
1 task done

Comments

@francisbooth
Copy link

Is there an existing issue for this?

  • I have searched the tracker for existing similar issues and I know that duplicates will be closed

Describe the Issue

When using variables within the raw body of a request sent as JSON, if the variable is passed within a string, I would expect the variable to escaped in the request.

Steps To Reproduce

  1. Create an variable (environment or global), e.g. foo="\"
  2. Create a request
  3. Select "body" tab
  4. Choose "raw"
  5. Choose "JSON" from the dropdown
  6. Add a JSON object to the body, e.g. { "foo": "{{foo}}" }
  7. Open the code right sidebar panel ...via the sidebar icon [</>]
  8. Inspect the request...

What I see: --data-raw '{ "foo": "\" }' ← backslash not escaped
What I would expect: --data-raw '{ "foo": "\\" }' ← N.B. escaped backslash

Screenshots or Videos

unescaped-backslash

Operating System

macOS

Postman Version

9.21.5

Postman Platform

Postman App

Additional Context?

No response

@francisbooth
Copy link
Author

francisbooth commented Oct 17, 2022

For more context... this is avoidable by reading the foo var and writing it as an escaped string to a temp var via a pre-request script and then adding escapedFoo to the JSON body.

This would be inconsistent with vars being contextually escaped in the URL context (for example) though.

@akshaydeo
Copy link

@francisbooth, thank you for reporting this issue. We are looking into fixing this; I will update the ticket as soon as we push the fix 🙇‍♂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants