stdlib-js / stdlib-js/stdlib

Regexp escape error with Regexp option 'u' and dash in string

Đang mở
#701 5 bình luận 0 reaction 1 người được giao Được @Planeshifter nhận Xem trên GitHub
Bug Documentation wont-fix
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ả

### Description

Encountered an error while escaping a string containing a `-` and passing it to `Regexp.new()` with `u` flag enabled

### Related Issues

_No response_

### Questions

_No response_

### Demo

https://codesandbox.io/s/node-playground-forked-edd4wv?file=/src/index.js

### Reproduction

```js
import rescape from "@stdlib/utils-escape-regexp-string";

console.log(new RegExp(rescape("en-US"))); //=> /en\-US/

console.log(new RegExp(rescape("en-US"), "u")); //=> SyntaxError: invalid identity escape in regular expression
```

### Expected Results

`console.log(new RegExp(rescape("en-US"), "u"))` should print `/en-US/`

### Actual Results

`console.log(new RegExp(rescape("en-US"), "u"))` raises an error with a message similar to the following:

```
SyntaxError: Invalid regular expression: /en\-US/: Invalid escape
```

### Version

@stdlib/utils-escape-regexp-string 0.0.9

### Environments

Node.js, Firefox, Chrome

### Browser Version

_No response_

### Node.js / npm Version

16

### Platform

_No response_

### Checklist

- [X] Read and understood the [Code of Conduct](https://github.com/stdlib-js/stdlib/blob/develop/CODE_OF_CONDUCT.md).
- [X] Searched for existing issues and pull requests.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.