Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/util/conditionalExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ class RegExpEvaluator implements FilterComparator {

constructor(rVal: unknown) {
// Support condVal: RegExp | string
// Keep the evaluator's lastIndex separate from the caller's regexp.
const condValue = this._condVal = isString(rVal) ? new RegExp(rVal)
: isRegExp(rVal) ? rVal as RegExp
: isRegExp(rVal) ? new RegExp(rVal)
: null;
if (condValue == null) {
let errMsg = '';
Expand All @@ -188,6 +189,8 @@ class RegExpEvaluator implements FilterComparator {
}

evaluate(lVal: unknown): boolean {
// Global and sticky regexps must test each data value independently.
this._condVal.lastIndex = 0;
const type = typeof lVal;
return isString(type) ? this._condVal.test(lVal as string)
: isNumber(type) ? this._condVal.test(lVal + '')
Expand Down
159 changes: 159 additions & 0 deletions test/ut/spec/data/filterTransformRegExp.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.