When using riteway/match, and the pattern you try to match is a string that contains regex meta characters, match does not behave as expected.
Example given;
const text = '<h1>Are there any cats?</h1>';
const pattern = 'Are there any cats?';
const contains = match(pattern);
/*
operator: deepEqual
expected: |-
'Are there any cats?'
actual: |-
'Are there any cats'
*/
match will try and match against the pattern Are there any cats and has omitted the ?, as it is interpreted as a regex meta character.
The code change in this PR escapes any regex meta characters when the supplied pattern is of type String. Please see the added test that documents this behaviour.
When using
riteway/match
, and the pattern you try to match is a string that contains regex meta characters,match
does not behave as expected.Example given;
match
will try and match against the patternAre there any cats
and has omitted the?
, as it is interpreted as a regex meta character.The code change in this PR escapes any regex meta characters when the supplied pattern is of type
String
. Please see the added test that documents this behaviour.