Skip to content

Commit

Permalink
Better ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Dec 11, 2018
1 parent ac03710 commit 4e82009
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/logstop.rb
Expand Up @@ -16,15 +16,15 @@ module Logstop
def self.scrub(msg, ip: false, scrubber: nil)
msg = msg.to_s

msg = msg.gsub(IP_REGEX, FILTERED_STR) if ip

# order filters are applied is important
msg = msg
.gsub(URL_PASSWORD_REGEX, FILTERED_URL_STR)
.gsub(EMAIL_REGEX, FILTERED_STR)
.gsub(CREDIT_CARD_REGEX, FILTERED_STR)
.gsub(PHONE_REGEX, FILTERED_STR)
.gsub(SSN_REGEX, FILTERED_STR)
.gsub(URL_PASSWORD_REGEX, FILTERED_URL_STR)
.gsub(EMAIL_REGEX, FILTERED_STR)

msg = msg.gsub(IP_REGEX, FILTERED_STR) if ip

msg = scrubber.call(msg) if scrubber

Expand Down
5 changes: 5 additions & 0 deletions test/logstop_test.rb
Expand Up @@ -47,6 +47,11 @@ def test_multiple
assert_filtered "test@example.org test2@example.org 123-45-6789", expected: "[FILTERED] [FILTERED] [FILTERED]"
end

def test_order
assert_filtered "123-45-6789@example.org"
assert_filtered "127.0.0.1@example.org", ip: true
end

def test_tagged_logging
str = StringIO.new
logger = ActiveSupport::Logger.new(str)
Expand Down

0 comments on commit 4e82009

Please sign in to comment.