gleam-lang / gleam-lang/stdlib
On JavaScript, string.replace \r splits \r\n graphemes
- Dominant language
- Gleam
- Stars
- 710
- Forks
- 225
- Avg merge
- 5h 52m
- Merged PRs (30d)
- 3
Description
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.
```gleam
import gleam/bit_array
import gleam/string
import gleeunit
import gleeunit/should
pub fn string_replace_test() {
// Check \r\n binary representation is as expected
"\r\n"
|> bit_array.from_string
|> bit_array.inspect
|> should.equal("<<13, 10>>")
// Test replacing \n with a space character (U+0020)
"\r\n"
|> string.replace("\n", " ")
|> bit_array.from_string
|> bit_array.inspect
|> should.equal("<<13, 32>>")
// Test replacing \r with a space character (U+0020) fails with:
//
// Values were not equal
// expected: "<<32, 10>>"
// got: "<<13, 10>>"
//
"\r\n"
|> string.replace("\r", " ")
|> bit_array.from_string
|> bit_array.inspect
|> should.equal("<<32, 10>>")
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.