Doerge
Hey everybody,
I get a response from a (pretty funky) API, and am trying to decode it with HTTPoison.
It fails with something like this:
{:error,
%Poison.ParseError{
data: " { \"config\": ...",
skip: 86293,
value: "\\ud83d"
}}
Toying around with it in IEx also doesn’t work:
iex(1)> tmp = "\ud83d"
** (SyntaxError) iex:1:8: invalid or reserved Unicode code point \u{d83d}. Syntax error after: \u
I’m not really sure how to proceed from here.
How can I clean up my string from invalid code points before decoding it? It’s ok for me to just drop the invalid ones, but I would like to keep the valid ones.
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
I’ve followed the Phoenix LiveView file upload code here Uploads — Phoenix LiveView v1.0.0-rc.7 and so far everything works just fine wit...
New
I’m using an Umbrella project for a Phoenix application, and I want to have one Ecto Repo and one PostgreSQL database shared by all apps....
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #iex
- #graphql
- #elixirconf-us
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
03juan
You could sanitise the raw response with
Enum.reducebefore trying to decode it, dropping each value that results in an incorrect codepoint.Doerge
I don’t know which ones are invalid, so I don’t really know which ones to drop?
Is there an allow-list of valid ones builtin somewhere?
Doerge
I realize that a single code point might not be meaningful in itself. Here is an actual value from the API response that also fails in IEx:
The response is a Javascript block. The above should be this emoji:
https://charbase.com/1f4cd-unicode-round-pushpin
I guess Javascript uses a different codepoint set, than Elixir? How do I tell Elixir or Poison to use Javascript’s?
03juan
That is a good question. Looks like String.chunk/2 is a good place to start to weed out invalid UTF8 characters. This section of the docs gives some more information. String — Elixir v1.20.2
As for emoji code points, there might be a library that can help with that but unfortunately this is as far as my knowledge extends on the subject.
I don’t think emoji fall into the official unicode spec, that may be part of the issue.
edit:
If you don’t want to keep the emoji at all then a simple
Enum.filter(raw, &String.valid?/1)should do the trick?al2o3cr
\ud83dis a Unicode “surrogate pair” character; it’s normally followed by another character of the\uDxxxvariety to represent a character above\uFFFFin UTF-16 systems. If there’s one in the text by itself (a “lone surrogate”) that string can’t be represented in UTF-8 at all and is invalid.Jasoncan parse these (when they are paired):But oddly, doesn’t produce them:
Doerge
Thanks for explaining, and pointing me to Jason! It works perfectly!
kip
Emoji are definitely part of the Unicode specification.
03juan
Yes that was an ignorant statement from my part from lack of research. Thanks for the correction.
DidactMacros
Old thread, but I encountered a somewhat adjacent issue with my file names. Character encodings over 1418 aren’t represented as their string forms, and you get a boxed question mark instead or a boxed question mark with a space, and character encodings over 553295 (553_295) cause a codepoint error with string conversion attempts.
(Maybe this is due to something that needs to be installed/configured on my computer?)
I had to filter out character lists with such encodings (ones over 553295) when passing :file.dir_list output elements to File.dir? because this function first converts character lists to strings, however lower encodings were still usable, even though they didn’t have distinct string representation.
al2o3cr
It’s difficult to narrow down what could be causing this because there are a lot of suspects: