Comments (5)
Having been pointed at gleam.mjs I can see it uses JSON.stringify
.
Quick interactive testing on the MDN page for JSON.stringify makes clear that all five special characters are properly escaped. I don't know if Node does anything differently, but assuming not mean this is incompatible behaviour between the two targets.
from stdlib.
Thank you. Let's get this fixed
from stdlib.
I'm not able to do this properly right now, but I was curious so I made a little test project that had only the relevant bits of gleam_stdlib.erl and fumbled with the Erlang docs for a bit. Replacing as follows seemed to do the trick:
% At line 349: %
% --- %
% Pattern = [$"],
% Replacement = [$\\, $\\, $&],
% Escaped = re:replace(Binary, Pattern, Replacement, [{return, binary}, global]),
% ["\"", Escaped, "\""];
% --- %
% +++ %
EscapedWithAngles = io_lib:format("~p", [Binary]),
lists:nth(3, hd(EscapedWithAngles));
% +++ %
This avoids doing a pass for each type of escaped character and, at least for the obvious tests I threw at it, works. If I've missed a subtle edge-case, or used something about the returned value of io_lib:format
I shouldn't, or otherwise committed an Erlang crime... please teach me!
from stdlib.
@DanielSherlock thanks I will take a look.
from stdlib.
Sorry, I took so long to type that out you'd basically fixed it in the mean time. I commented on the PR too, but after all that I like the clear way your solution reads and it means we don't have to worry about whether io_lib:format
always returns something of the same shape.
from stdlib.
Related Issues (20)
- list.try_each function HOT 3
- result.try function HOT 1
- 0.28.1 Changelog missing
- `dynamic` documentation error
- how to interact with files or IO devices using the stdlib? HOT 1
- gleam/io.debug fails on javascript target where process.stderr is not defined HOT 1
- Redefinition of type `dynamic` in OTP 26 HOT 1
- Question: Is there a "system call" in Gleam? HOT 2
- 0.29 release missing on gh HOT 1
- move to new ´@if´ syntax for target selection HOT 5
- Should we have list.concat? HOT 9
- move function.tap somewhere else before 1.0 HOT 1
- string.inspect should print non-byte bit strings with Gleam syntax HOT 8
- Exclusive range HOT 5
- Map equality in JavaScript target is faulty and not commutative HOT 1
- Extend `float.parse` to parse strings with no decimal point HOT 1
- Change `{thing}.filter` label for the predicate argument HOT 2
- Proposal: Use Javascript Iterators and Generators HOT 9
- `Maps are not ordered` seems to be inaccurate for the erlang target! HOT 1
- int.random behaviour HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stdlib.