abelard12 has asked for the wisdom of the Perl Monks concerning the following question:
I'm using JSON::XS to generate an ld+json object. I'm not clear on what the correct way is to escape string literal values.
JSON::PP has an escape_slash() method. JSON::XS does not. But there is also a Cpanel::JSON::XS fork that does implement it.
Cpanel::JSON::XS includes this note:
According to the JSON Grammar, the forward slash character (U+002F) "/" need to be escaped. But by default strings are encoded without escaping slashes in all perl JSON encoders.
So what is best practice? Why doesn't JSON::XS offer the escape_slash() method? Is it a false sense of security? If so, what's the safest route? To escape all of the strings in the data structure before encoding to JSON?
It seems like having an escape option as part of the JSON encoding would be less error-prone. What are y'all doing?
This page talks about the problem and recommends using jsesc with Node: https://www.man42.net/blog/2016/12/safely-escape-user-data-in-a-script-tag/
What's the equivalent of jsesc for Perl?
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: JSON::XS and escaping literal strings
by choroba (Cardinal) on Jun 06, 2018 at 23:21 UTC | |
by abelard12 (Novice) on Jun 06, 2018 at 23:37 UTC | |
by tobyink (Canon) on Jun 07, 2018 at 06:38 UTC | |
by Anonymous Monk on Jun 07, 2018 at 21:27 UTC | |
by Anonymous Monk on Jun 08, 2018 at 01:57 UTC | |
| |
|
Re: JSON::XS and escaping literal strings
by Your Mother (Archbishop) on Jun 06, 2018 at 23:11 UTC |