dleitee / dleitee/strman

Not many tests for multibyte Unicode characters

Open
#66 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2k
Forks
77
PR merge metrics
No merged PRs in 30d

Description

It's great to find a library like this, string manipulation in JS often leaves much to be desired. However, the limited scope of testing with strings containing multibyte Unicode characters is concerning. Multibyte characters often create quite a few headaches. (These's a [nice writeup about the challenges here](https://mathiasbynens.be/notes/javascript-unicode))

There are already a few tests that check the processing of multibyte characters, e.g. [decencode.test.js](https://github.com/dleitee/strman/blob/3f85db8997a0867f1d9a6f4785adbab219bfaf3b/test/decencode.test.js#L5). Having more tests to ensue safe handling of strings containing multibyte characters would be a wonderful addition!

Understandably, it might not be possible for all functions to safely support multibyte characters. Perhaps this could be documented as a limitation on these functions?

## Simple example of current behavior:

```
$ pwd
~/strman
$ node -v
v7.9.0

$ node -e 'console.log("A".length);'
1
$ node -e 'console.log("漢".length);'
1
$ node -e 'console.log("\u200B".length);'
1
$ node -e 'console.log("🐨".length);'
2

$ node -e 'console.log(require("./lib/strman.js").last("A"));'
A
$ node -e 'console.log(require("./lib/strman.js").last("漢"));'

$ node -e 'console.log(require("./lib/strman.js").last("🐨"));'
🐨

$ node -e 'console.log(require("./lib/strman.js").reverse("A"));'
A
$ node -e 'console.log(require("./lib/strman.js").reverse("漢"));'

$ node -e 'console.log(require("./lib/strman.js").reverse("🐨"));'
��
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.