fast-redact
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -52,2 +52,17 @@ 'use strict' | ||
/** | ||
* Creates the body of the restore function | ||
* | ||
* Restoration of the redacted object happens | ||
* backwards, in reverse order of redactions, | ||
* so that repeated redactions on the same object | ||
* property can be eventually rolled back to the | ||
* original value. | ||
* | ||
* This way dynamic redactions are restored first, | ||
* starting from the last one working backwards and | ||
* followed by the static ones. | ||
* | ||
* @returns {string} the body of the restore function | ||
*/ | ||
function restoreTmpl (resetters, paths, hasWildcards) { | ||
@@ -57,3 +72,3 @@ const dynamicReset = hasWildcards === true ? ` | ||
const len = keys.length | ||
for (var i = ${paths.length}; i < len; i++) { | ||
for (var i = len - 1; i >= ${paths.length}; i--) { | ||
const k = keys[i] | ||
@@ -69,6 +84,6 @@ const o = secret[k] | ||
const secret = this.secret | ||
${dynamicReset} | ||
${resetters} | ||
${dynamicReset} | ||
return o | ||
` | ||
} |
{ | ||
"name": "fast-redact", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "very fast object redaction", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -990,2 +990,34 @@ 'use strict' | ||
test('correctly restores keys matching a static path and a wildcard', ({ end, is }) => { | ||
const redact = fastRedact({ | ||
paths: ['a', '*.b', 'x.b'], | ||
serialize: false | ||
}) | ||
const o = { x: { a: 'a', b: 'b' } } | ||
redact(o) | ||
is(o.x.a, 'a') | ||
is(o.x.b, '[REDACTED]') | ||
redact.restore(o) | ||
is(o.x.a, 'a') | ||
is(o.x.b, 'b') | ||
end() | ||
}) | ||
test('correctly restores keys matching multiple wildcards', ({ end, is }) => { | ||
const redact = fastRedact({ | ||
paths: ['a', '*.b', 'x.*', 'y.*.z'], | ||
serialize: false | ||
}) | ||
const o = { x: { a: 'a', b: 'b' }, y: { f: { z: 'z' } } } | ||
redact(o) | ||
is(o.x.a, '[REDACTED]') | ||
is(o.x.b, '[REDACTED]') | ||
is(o.y.f.z, '[REDACTED]') | ||
redact.restore(o) | ||
is(o.x.a, 'a') | ||
is(o.x.b, 'b') | ||
is(o.y.f.z, 'z') | ||
end() | ||
}) | ||
test('handles multiple paths with leading brackets', ({ end, is }) => { | ||
@@ -992,0 +1024,0 @@ const redact = fastRedact({ paths: ['["x-y"]', '["y-x"]'] }) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71825
1612