NLF

NLF

Replacing ">" and "<" with Unicode code point for. json encoding

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! :smiley:

Most Liked

03juan

03juan

Welcome to the forum :rocket:

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/lib/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​]

Last Post!

03juan

03juan

I meant ?> is missing

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New

Other popular topics Top

vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement