Skip to content

Commit be8a9b7

Browse files
fix(redact): redact emails inside strings MONGOSH-1392 (#404)
* fix(redact): redact emails inside strings MONGOSH-1392 * refactor: combine rules
1 parent 6f9e6b5 commit be8a9b7

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/mongodb-redact/src/index.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ describe('mongodb-redact', function () {
7777
expect(redact('[email protected]')).to.equal('<email>');
7878
});
7979

80+
it('should redact emails inside strings', function () {
81+
expect(
82+
redact(
83+
'"db.test.insert({ email: "[email protected]" })"'
84+
)
85+
).to.equal('"db.test.insert({ email: "<email>" })"');
86+
});
87+
8088
it('should redact ip addresses', function () {
8189
expect(redact('10.0.0.1')).to.equal('<ip address>');
8290
});

packages/mongodb-redact/src/regexes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export const regexes = [
2323

2424
// Email addresses
2525
[
26-
/(^|[ \t\r\n\v\f])([a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]{1,64}@[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?){1,500})/gim,
27-
'$1<email>',
26+
/(^|[ \t\r\n\v\f"'`])([a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]{1,64}@[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(["'`]?)){1,500})/gim,
27+
'$1<email>$6',
2828
],
2929

3030
// IP addresses

0 commit comments

Comments
 (0)