From 3004c8832ab5fd35a1d1a7d2dfa99221b5dfd1f7 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 6 Dec 2021 08:01:05 -0500 Subject: [PATCH] Fix `dig-snfe modifiers` to properly detect changes in results --- platform/dig/snfe.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/platform/dig/snfe.js b/platform/dig/snfe.js index 43386ca6b..f4b9b43ac 100644 --- a/platform/dig/snfe.js +++ b/platform/dig/snfe.js @@ -227,7 +227,7 @@ async function matchRequestModifiers(engine, requests) { modified = true; if ( NEED_RESULTS ) { const reqstop = process.hrtime.bigint(); - details.f = directives.map(a => a.logData().raw).sort().join(' '); + details.f = directives.map(a => `${a.result}:${a.logData().raw}`).sort(); details.t = Math.round(Number(reqstop - reqstart) / 10) / 100; results['csp'].push([ i, Object.assign({}, details) ]); } @@ -240,7 +240,7 @@ async function matchRequestModifiers(engine, requests) { modified = true; if ( NEED_RESULTS ) { const reqstop = process.hrtime.bigint(); - details.f = directives.map(a => a.logData().raw).sort().join(' '); + details.f = directives.map(a => `${a.result}:${a.logData().raw}`).sort(); details.t = Math.round(Number(reqstop - reqstart) / 10) / 100; results['redirect-rule'].push([ i, Object.assign({}, details) ]); } @@ -253,7 +253,7 @@ async function matchRequestModifiers(engine, requests) { modified = true; if ( NEED_RESULTS ) { const reqstop = process.hrtime.bigint(); - details.f = directives.map(a => a.logData().raw).sort().join(' '); + details.f = directives.map(a => `${a.result}:${a.logData().raw}`).sort(); details.t = Math.round(Number(reqstop - reqstart) / 10) / 100; results['removeparam'].push([ i, Object.assign({}, details) ]); } @@ -298,13 +298,25 @@ async function compareModifiers(afterResults) { const after = new Map(afterResults[modifier]); for ( const [ i, b ] of before ) { const a = after.get(i); - if ( a !== undefined && a.f === b.f ) { continue; } - diffs.push([ i, { before: b, after: a || null } ]); + if ( a !== undefined && JSON.stringify(a.f) === JSON.stringify(b.f) ) { continue; } + diffs.push([ i, { + type: b.type, + url: b.url, + originURL: b.originURL, + before: { f: b.f, t: b.t }, + after: a !== undefined ? { f: a.f, t: a.t } : null, + }]); } for ( const [ i, a ] of after ) { const b = before.get(i); if ( b !== undefined ) { continue; } - diffs.push([ i, { before: b || null, after: a } ]); + diffs.push([ i, { + type: a.type, + url: a.url, + originURL: a.originURL, + before: null, + after: { f: a.f, t: a.t }, + }]); } } return diffs;