Algorithm to pad string is not Unicode aware
- Ngôn ngữ chính
- JavaScript
- Star
- 6k
- Fork
- 1.3k
- Merge trung bình
- 1 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 611
Mô tả
## Checklist
> Please ensure the following tasks are completed before filing a bug report.
- [x] Read and understood the [Code of Conduct][code-of-conduct].
- [x] Searched for existing issues and pull requests.
## Description
> Description of the issue.
Encountered an error when attempting to pad a string based on the number of visual characters. Currently, we rely on `String#length` to determine the number of characters to pad; however, this returns the number of code points, which may not be same as the number of graphemes.
We should consider how to properly handle Unicode characters comprised of multiple code points.
## Related Issues
> Does this issue have any related issues?
No.
## Questions
> Any questions for reviewers?
No.
## Other
> Any other information relevant to this issue? This may include screenshots, references, stack traces, sample output, and/or implementation notes.
This affects the following packages:
- [`@stdlib/string/left-pad`](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/left-pad)
- [`@stdlib/string/right-pad`](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/right-pad)
- [`@stdlib/string/pad`](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/pad)
#### Demo
> If relevant, provide a link to a live demo.
N/A
#### Reproduction
> What steps are required to reproduce the unexpected output?
In order to reproduce this bug, do the following:
- attempt to pad using an input string containing surrogate pairs or by providing a string with which to pad containing surrogate pairs.
#### Expected Results
> What are the expected results?
I might expect that I would see padding based on the number of visual characters. Currently, the implementation runs the risk of unpaired surrogates.
#### Actual Results
> What are the actual results?
N/A
#### Environments
> What environments are affected (e.g., `Node v0.4.x`, `Chrome`, `IE 11`)? If Node.js, include the `npm` version, operating system, and any other potentially relevant platform information.
The following environments are affected:
- all
[code-of-conduct]: https://github.com/stdlib-js/stdlib/blob/develop/CODE_OF_CONDUCT.md
Hướng dẫn đóng góp
Hướng nghiên cứu
Start by inspecting the implementations of @stdlib/string/left-pad, @stdlib/string/right-pad, and @stdlib/string/pad, focusing on their use of String#length. Reproduce the behavior with strings containing surrogate pairs, then verify that padding is based on visual characters and does not produce unpaired surrogates.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript
- Lĩnh vực
- tooling
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100