From 6168a62c57da968bfeda6cb8382d8c3ed1e7a749 Mon Sep 17 00:00:00 2001 From: Jared Betteridge Date: Tue, 1 Aug 2017 11:12:19 -0600 Subject: [PATCH] feat: support for redacting URLs (#8) --- lib/firstNames.json | 18 +++--------------- lib/patterns.js | 3 ++- test/index.test.js | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/firstNames.json b/lib/firstNames.json index 843ad65..87bba39 100644 --- a/lib/firstNames.json +++ b/lib/firstNames.json @@ -329,7 +329,6 @@ "barbar", "barbara", "barbera", - "barbie", "barbra", "barrie", "basilia", @@ -869,7 +868,6 @@ "dayna", "daysi", "deadra", - "dean", "deana", "deandra", "deandrea", @@ -994,7 +992,6 @@ "donella", "donetta", "donette", - "dong", "donita", "donna", "donnetta", @@ -1275,7 +1272,6 @@ "florentina", "floretta", "floria", - "florida", "florinda", "florine", "florrie", @@ -1295,7 +1291,6 @@ "francisca", "francisco", "francoise", - "frank", "frankie", "fransisca", "fred", @@ -1557,7 +1552,6 @@ "jacelyn", "jacinda", "jacinta", - "jack", "jackeline", "jackelyn", "jacki", @@ -2423,7 +2417,6 @@ "lynne", "lynnette", "lynsey", - "ma 50", "mabel", "mabelle", "mable", @@ -2818,7 +2811,6 @@ "myrtis", "myrtle", "myung", - "nada", "nadene", "nadia", "nadine", @@ -2844,6 +2836,7 @@ "natalya", "natasha", "natashia", + "nate", "nathalie", "natisha", "natividad", @@ -2872,7 +2865,6 @@ "nettie", "neva", "nevada", - "nga", "ngan", "ngoc", "nguyet", @@ -2924,7 +2916,6 @@ "norma", "norman", "nubia", - "numbers", "nydia", "nyla", "obdulia", @@ -2946,6 +2937,7 @@ "olivia", "ollie", "olympia", + "omar", "oneida", "onie", "onita", @@ -3069,6 +3061,7 @@ "raylene", "raymond", "raymonde", + "raymund", "rayna", "rea", "reagan", @@ -3457,7 +3450,6 @@ "sixta", "skye", "slyvia", - "so 10", "socorro", "sofia", "soila", @@ -3504,13 +3496,11 @@ "stevie", "suanne", "sudie", - "sue", "sueann", "suellen", "suk", "sulema", "sumiko", - "sunday", "sunni", "susan", "susana", @@ -3804,7 +3794,6 @@ "venice", "venita", "vennie", - "venus", "veola", "vera", "verda", @@ -3837,7 +3826,6 @@ "vicki", "vickie", "vicky", - "victor", "victoria", "victorina", "vida", diff --git a/lib/patterns.js b/lib/patterns.js index 3e87ad1..41afeb9 100644 --- a/lib/patterns.js +++ b/lib/patterns.js @@ -20,5 +20,6 @@ module.exports = { company: /([A-Z&][\w,]* )+(I[Nn][Cc](orporated)?|C[Oo](rp(oration)?)?|LLP|llc|LLC|plc|gmbh)\.?(\b|$)/g, salutation: /(^|\n(\s+)?)(dear|hi|hey|hello|greetings) ([^,:;\s]+(,? )?){1,5}[,;\n]/gi, valediction: /([Tt]hank(s| you)( for [^!,.]+| again)?|[Cc]heers|[Ss]incerely|[Rr]egards|[Rr]espectfully|[Bb]est|[Bb]est regards|[Yy]ours truly)\s*[!,.]?\s*([A-Z&]([\w&]+)?\.?( )?)+[^a-z]*$/g, - digits: /\d+/g + digits: /\d+/g, + url: /([^\s:/?#]+):\/\/([^/?#\s]*)([^?#\s]*)(\?([^#\s]*))?(#([^\s]*))?\b/ }; diff --git a/test/index.test.js b/test/index.test.js index 692367a..f17233f 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -167,4 +167,18 @@ defineTest('index.js', function (Redactor) { redactor.redact('codeA: 123, codeB: 678').should.equal('codeA: DIGITS, codeB: DIGITS'); }); + it('should replace URLs', function () { + redactor.redact('My homepage is http://example.com').should.equal('My homepage is URL'); + redactor.redact('ip http://127.0.01/example.html test').should.equal('ip URL test'); + redactor.redact('custom protocol myapp://example.com').should.equal('custom protocol URL'); + redactor.redact('Reset password url is https://example.com/reset/password/12345').should.equal('Reset password url is URL'); + redactor.redact('complex http://user@pass:example.com:8080/reset/password/12345?foo=bar&hi=there#/app works?').should.equal('complex URL works?'); + redactor.redact('before http://www.example.com after').should.equal('before URL after'); + redactor.redact('before http://www.example.com:123 after').should.equal('before URL after'); + redactor.redact('before http://www.example.com/foo after').should.equal('before URL after'); + redactor.redact('before http://www.example.com/foo/bar after').should.equal('before URL after'); + redactor.redact('before http://www.example.com/foo/bar?foo=bar after').should.equal('before URL after'); + redactor.redact('before http://www.example.com/foo/bar?foo=bar#/foo/bar after').should.equal('before URL after'); + }); + });