Comments (5)
Sorry for bothering. I misinterpreted the output of the browser console. You are totaly right and I got it wrong.
from mongoose.
Would you be so kind to fill the issue template ? I'm sure this will be a great reading once you decode what you want to do and what you got, for me, so I don't have to infer that from your code and your outputs. If this is our bug, we'll fix it sooner.
Yeah, the title helps, but please, will you ?
Thank you.
from mongoose.
Sorry for being lazy 😄. Updated.
from mongoose.
The first test string seems to be the escape of an already escaped \n
, that is \\n
.
"{\"1\": \"a\\\\nb\"}"
is C for {"1": "a\\nb"}
. The double backslash is unescaped and the string returned as {"1": "a\nb"}
.
The second test string to be parsed contains a backslash and its corresponding character.
"{\"1\": \"a\\nb\"}"
is C for {"1": "a\nb"}
, that is what mg_json_unescape()
sees and correctly processes, so the output would be {"1": "ab"}
Lines 292 to 293 in 6386cdf
See real stuff with `mg_hexdump()"
char *test = "{\"1\": \"a\\\\nb\"}";
char* temp = mg_json_get_str(mg_str(test), "$.1");
MG_INFO(("In:"));
mg_hexdump(test, strlen(test));
MG_INFO(("Out:"));
mg_hexdump(temp, strlen(temp));
test = "{\"1\": \"a\\nb\"}";
temp = mg_json_get_str(mg_str(test), "$.1");
MG_INFO(("In:"));
mg_hexdump(test, strlen(test));
MG_INFO(("Out:"));
mg_hexdump(temp, strlen(temp));
$ ./fr13
4d1fb5a 2 fr13.c:7:main In:
0000 7b 22 31 22 3a 20 22 61 5c 5c 6e 62 22 7d {"1": "a\\nb"}
4d1fb5a 2 fr13.c:9:main Out:
0000 61 5c 6e 62 a\nb
4d1fb5a 2 fr13.c:15:main In:
0000 7b 22 31 22 3a 20 22 61 5c 6e 62 22 7d {"1": "a\nb"}
4d1fb5a 2 fr13.c:17:main Out:
0000 61 0a 62 a.b
What I think you are observing is your JavaScript console processing the first \n and escaping it for you when printing it.
I'd like to see your actual use case and whether this has an actual problem that needs to be solved.
from mongoose.
What I was trying to point out is that "a\nb"
is not valid json and the \n should not lead to being parsed as new line, while "a\\nb"
is valid json (double escaping is strictly required) but is not unescaped at all.
JSON.parse('"a\nb"')
Uncaught SyntaxError:
JSON.parse('"a\\nb"')
'a\nb'
edit:
JSON.stringify(`a
b`)
'"a\\nb"'
I only used console.log to visualize the new line when the valid json gets unescaped in e.g. a browser.
So the current implementation just does not work with valid json and additionally accepts invalid json that can not be used otherwise.
from mongoose.
Related Issues (20)
- Chunked message body incorrectly terminated on `\r\n\r\n` instead of `0\r\n\r\n`
- About running on a riscv-linux HOT 1
- MG_EV_CLOSE is fired before MG_EV_HTTP_MSG HOT 16
- RP2040 W5500 and DHCP HOT 14
- POST and TLS client HOT 11
- gcc warning in builtin TLS code HOT 2
- Unbounded growth in transmit buffer with WebSockets HOT 8
- Bus error crash in the new mg_wakeup() function HOT 4
- how to config in mbed ?
- Prefix PHY_* constants in STM32 drivers with MG_ to avoid name conflicts
- Rename MG_ENABLE_FILE to MG_ENABLE_POSIX_FS
- MG_ARCH_FREERTOS_LWIP is not available in Mongoose 7.12 HOT 1
- Mongoose documentation SSL/TLS tutorial is inaccurate for mg_tls_opts. HOT 2
- Mongoose prematurely closes connections when the second request in a pipeline is invalid
- Mongoose closes the connection without responding to POST requests that don't have explicit lengths HOT 2
- Discrepancy Between Mongoose Versions on Espressif Component Registry and Official Release HOT 1
- The maximum DNS response count should be a larger value HOT 1
- Mbedtls error and memory leak when connecting through WebSocket HOT 1
- Reading post data from https connection fails now and then HOT 24
- bind define conflict between "lwip/sockets.h" and c++ <functional> HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongoose.