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

json.Unescape has issues with UNC paths #121

Open
richard-mauri opened this issue Apr 8, 2022 · 0 comments
Open

json.Unescape has issues with UNC paths #121

richard-mauri opened this issue Apr 8, 2022 · 0 comments

Comments

@richard-mauri
Copy link

richard-mauri commented Apr 8, 2022

I have a test string that has a value with an escaped UNC path in it .
It validates ok according to: https://jsonlint.com/

"{\"dataPath\":\"\\\\bnk11977fs\\bnk11977\\xyz11146682\\xyzdata\\\"}"

When you pass it through json.Unescape the result is invalid json

See: playground

Highlights from the stdout are:

raw sample0 "\"{\\\"dataPath\\\":\\\"\\\\\\\\bnk11977fs\\\\bnk11977\\\\be11146682\\\\encompassdata\\\\\\\"}\""

unescape for sample0 was invalidated "{\"dataPath\":\"\\\\bnk11977fs\\bnk11977\\be11146682\\encompassdata\\\"}" ; error=json: invalid character 'e' in string escape code: "\\bnk11977fs\bnk11977\be1114668...

You may ask, "If the original is valid json, then why do you need to unescape it anyway?"

Answer: The raw escaped form comes from reading a logging entry.
A log processor service (lambda) needs to create output without all the escapes, else another downstream reader (logstash ingest) see's the dcument event as a big ass string and not a nice nested object.

So the goal is to be able to have the lambda processor write the line something like the following.
yes the UNC and escapes are a bitch

And this is a simple example. Imagine a raw json with 100 deply nested fields.
You certinly can't just blind Replacement of backslash-quote with quote !

{"dataPath":"\\bnk11977fs\bnk11977\be11146682\encompassdata\"}

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

No branches or pull requests

1 participant