Code review of `trusted-replace-node-text` scriptlet

This commit is contained in:
Raymond Hill 2024-07-22 09:51:40 -04:00
parent ec568b614d
commit bf75dc2f90
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 14 additions and 6 deletions

View File

@ -714,8 +714,12 @@ function replaceNodeTextFn(
const reNodeName = safe.patternToRegex(nodeName, 'i', true);
const rePattern = safe.patternToRegex(pattern, 'gms');
const extraArgs = safe.getExtraArgs(Array.from(arguments), 3);
const reIncludes = safe.patternToRegex(extraArgs.includes || extraArgs.condition || '', 'ms');
const reExcludes = safe.patternToRegex(extraArgs.excludes || '.^', 'ms');
const reIncludes = extraArgs.includes || extraArgs.condition
? safe.patternToRegex(extraArgs.includes || extraArgs.condition, 'ms')
: null;
const reExcludes = extraArgs.excludes
? safe.patternToRegex(extraArgs.excludes, 'ms')
: null;
const stop = (takeRecord = true) => {
if ( takeRecord ) {
handleMutations(observer.takeRecords());
@ -728,10 +732,14 @@ function replaceNodeTextFn(
let sedCount = extraArgs.sedCount || 0;
const handleNode = node => {
const before = node.textContent;
reIncludes.lastIndex = 0;
if ( safe.RegExp_test.call(reIncludes, before) === false ) { return true; }
reExcludes.lastIndex = 0;
if ( safe.RegExp_test.call(reExcludes, before) ) { return true; }
if ( reIncludes ) {
reIncludes.lastIndex = 0;
if ( safe.RegExp_test.call(reIncludes, before) === false ) { return true; }
}
if ( reExcludes ) {
reExcludes.lastIndex = 0;
if ( safe.RegExp_test.call(reExcludes, before) ) { return true; }
}
rePattern.lastIndex = 0;
if ( safe.RegExp_test.call(rePattern, before) === false ) { return true; }
rePattern.lastIndex = 0;