parse is swallowing literal characters preceding dot (.) when pattern contains a brace expression (original) (raw)
If the pattern has literal characters before a dot (.), and a brace expression after the dot, the parse function swallows the literal characters that precede the dot.
Consider the following example:
require('picomatch').makeRe('1.{0..9}')
Here's what we expect to see:
However, what we see instead is:
Notice that not only is the 1 missing, the dot is not escaped.
We can find evidence of this problem by inspecting the output of parse.
{ input: '1.{0..9}', consumed: '1.{0.9}', output: '.[0-9]', ... }
The workaround for this behavior is to enclose the literal characters in a pair of round brackets.
require('picomatch').makeRe('(1).{0..9}')
Aside from the additional group, we now get the output we expect from the earlier pattern:
The described problem seems to only happen if at least one brace expression is present in the pattern and it comes after the dot.