'Newline' not escaped when passed as string to HTTP request
Self Checks
- [X] This is only for bug report, if you would like to ask a quesion, please head to Discussions.
- [X] I have searched for existing issues search for existing issues, including closed ones.
- [X] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
- [X] Pleas do not modify this template :) and fill in all the required fields.
Dify version
0.6.6
Cloud or Self Hosted
Cloud
Steps to reproduce
- Pass a text with a newline char (not \n) to HTTP request block
- Newline char is converted to \n
- All other special chars are escaped, but not \n
✔️ Expected Behavior
- Expected newline to be escaped like \n and other special chars are
❌ Actual Behavior
- All other special chars are escaped, but newline is just converted to \n without being escaped
It appears the issue you're encountering with newline characters not being properly escaped in HTTP requests sent from Dify version 0.6.6 stems from how the data is handled before being serialized to JSON and sent. In JSON, special characters like newline (\n), carriage return (\r), and tab (\t) are expected to be escaped to ensure correct interpretation by the server receiving the JSON payload. This escaping is typically managed by the JSON serializer, which, in the context of Dify, would be utilized by Axios when sending JSON data.
If newline characters are not being escaped as expected, it suggests a potential issue in the preparation of data before it's passed to the sendRequest method or a specific interpretation behavior of Axios or the receiving server regarding newline characters within JSON strings. The Dify code that constructs HTTP requests does not modify the data parameter before passing it to Axios, which means the data is sent as-is.
There are no known issues with Axios or within the Dify repository that specifically address the handling or escaping of newline characters in HTTP requests. Additionally, there's no distinction mentioned between the cloud-hosted and self-hosted versions of Dify regarding how newline characters in HTTP requests are handled.
To address this issue, you might consider manually escaping newline characters in your input data or verifying how the server interprets the received JSON payload. This approach ensures that newline characters are correctly understood by the server, aligning with the JSON specification's requirements for character escaping.
Details
Sources
About Dosu This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
To continue the conversation, mention @dosu.
In which field do you add a new line? Could you please provide a screenshot?