esamattis / esamattis/underscore.string

words' regex argument crashes with quantifiers

Open
#194 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
3.4k
Forks
367
PR merge metrics
No merged PRs in 30d

Description

As soon as I add a quantifier in `words`' pattern argument, I get an error I wouldn't with the original JS method split:

``` javascript
var a = _('1 2, 3').words(/, +/);
// => SyntaxError: Invalid regular expression: /^, ++|, ++$/: Nothing to repeat
var b = _('1 2, 3').words(/, */);
// => SyntaxError: Invalid regular expression: /^, *+|, *+$/: Nothing to repeat
var c = _.words('1 2, 3', /, */)
// => SyntaxError: Invalid regular expression: /^, *+|, *+$/: Nothing to repeat
```

See this jsfiddle: http://jsfiddle.net/ejoubaud/J9gn9/

Unrelated: Why use the obscure name `words` instead of the basic JS/Ruby well-known `split` ? I'd strongly +1 an alias.

Apart from that awesome job with this lib guys, thank you very much.

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.