-
-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
On JavaScript, string.replace \r splits \r\n graphemes #584
Comments
Thank you |
This is a bit subtle, but as far as I can tell from skimming through the Erlang/OTP First, check out
For trying to use the
So, (as far as I can tell from going through the Erlang/OTP code right now), that's how the |
Yep agreed it's due to the
So the question is which of JS or Erlang is the desired/intended behaviour? Should it replace by codepoint or by grapheme cluster 🤔. |
Sounds like the JS implementation is incorrect. |
Erlang's splitting behaviour seems inconsistent though import gleam/should
import gleam/string
pub fn split_newline_test() {
string.split("\r\n","\n")
|> should.equal(["\r",""])
} Meaning Erlang just like Javascript is perfectly ok with removing the However Erlang is not ok with import gleam/should
import gleam/string
pub fn split_newline_test() {
string.split("\r\n","\r")
|> should.equal(["","\n"])
} whereas Javascript is. |
I would have expected Erlang to reject attempting to split a |
So if we want to fully copy what Erlang does we need to ensure Javascript still DOES split on Edit:
import gleam/should
import gleam/string
pub fn split_newline_test() {
string.split("thing\r\nthing","\n")
|> should.equal(["thing","thing"])
} Both sequences are semantically the same in most cases and leaving a dangling |
I was expecting
string.replace
to treat control characters like any other code points, but then ran into this behaviour which looks wrong.The issue is only on the Erlang target, works fine under JS.
I can dig a bit deeper if it would be helpful, possible that other control characters are affected too.
The text was updated successfully, but these errors were encountered: