NLF
March 29, 2022, 5:03pm
1
Hello everyone after few hours of looking at docs and googling I still can’t for the love of me figure out how to mirror the json_encode in PHP json_encode
with JSON_HEX_TAG which according to documentation here convert
All < and > are converted to \u003C and \u003E.
I know that using Jason_encode with the escape: :html_safe
tag will will convert the ‘<’ with the proper unicode but NOT ‘>’ .
What’s the most convenient way to fix this?
Thanks!
03juan
March 29, 2022, 7:12pm
2
Welcome to the forum
There is an open issue about this from 20d ago, and it definitely seems like a bug. html_safe encoding bug · Issue #151 · michalmuskala/jason · GitHub
This line in the code jason/encode.ex at master · michalmuskala/jason · GitHub is where the angle brackets should be encoded, and <
is absent.
html_ranges = [{0x00..0x1F, :unicode}, {?<, :unicode}, {?/, ?/} | slash_escapes]
1 Like
03juan
March 29, 2022, 7:16pm
3
Maybe for now do your own String.replace
until the bug is fixed. Or fork the repo, update the code for your use, and submit a PR to fix upstream.