From 12e92e540dde802937f1ede2fe61ceb6cea6b97f Mon Sep 17 00:00:00 2001 From: Rodric Rabbah Date: Thu, 31 Oct 2019 16:52:22 -0400 Subject: [PATCH] Fix regex for log stripping. --- commands/util.go | 2 +- commands/util_test.go | 28 +++++++++++++++------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/commands/util.go b/commands/util.go index c3fd7526b..0a4e873cd 100644 --- a/commands/util.go +++ b/commands/util.go @@ -277,7 +277,7 @@ func stripTimestamp(log string) (strippedLog string) { // the timestamp expected format is YYYY-MM-DDTHH:MM:SS.[0-9]+Z // an optional " stdout" or " stderr" stream identifier // and the rest as the log line - regex := regexp.MustCompile("\\d{4}-[01]{1}\\d{1}-[0-3]{1}\\d{1}T[0-2]{1}\\d{1}:[0-6]{1}\\d{1}:[0-6]{1}\\d{1}.\\d+Z( (stdout|stderr):)?\\s(.*)") + regex := regexp.MustCompile("\\d{4}-[01]{1}\\d{1}-[0-3]{1}\\d{1}T[0-2]{1}\\d{1}:[0-6]{1}\\d{1}:[0-6]{1}\\d{1}.\\d+Z( *(stdout|stderr):)?\\s(.*)") match := regex.FindStringSubmatch(log) if len(match) > 3 && len(match[3]) > 0 { diff --git a/commands/util_test.go b/commands/util_test.go index 1350d8ab4..67e26b0db 100644 --- a/commands/util_test.go +++ b/commands/util_test.go @@ -26,19 +26,21 @@ import ( func TestStripTimestamp(t *testing.T) { logs := map[string]string{ - "2018-05-02T19:33:32.829992819Z stdout: this is stdout stderr: this is still stdout": "this is stdout stderr: this is still stdout", - "2018-05-02T19:33:32.829992819Z stderr: this is stderr stdout: this is still stderr": "this is stderr stdout: this is still stderr", - "2018-05-02T19:33:32.89Z stdout: this is stdout": "this is stdout", - "2018-05-02T19:33:32.89Z this is a msg": "this is a msg", - "2018-05-02T19:33:32.89Z this is a msg": " this is a msg", - "anything stdout: this is stdout": "anything stdout: this is stdout", - "anything stderr: this is stderr": "anything stderr: this is stderr", - "stdout: this is stdout": "stdout: this is stdout", - "stderr: this is stderr": "stderr: this is stderr", - "this is stdout": "this is stdout", - "this is stderr": "this is stderr", - "something": "something", - "": ""} + "2018-05-02T19:33:32.829992819Z stdout: this is stdout stderr: this is still stdout": "this is stdout stderr: this is still stdout", + "2018-05-02T19:33:32.829992819Z stderr: this is stderr stdout: this is still stderr": "this is stderr stdout: this is still stderr", + "2018-05-02T19:33:32.829992819Z stdout: this is stdout stderr: this is still stdout": "this is stdout stderr: this is still stdout", + "2018-05-02T19:33:32.829992819Z stderr: this is stderr stdout: this is still stderr": "this is stderr stdout: this is still stderr", + "2018-05-02T19:33:32.89Z stdout: this is stdout": "this is stdout", + "2018-05-02T19:33:32.89Z this is a msg": "this is a msg", + "2018-05-02T19:33:32.89Z this is a msg": " this is a msg", + "anything stdout: this is stdout": "anything stdout: this is stdout", + "anything stderr: this is stderr": "anything stderr: this is stderr", + "stdout: this is stdout": "stdout: this is stdout", + "stderr: this is stderr": "stderr: this is stderr", + "this is stdout": "this is stdout", + "this is stderr": "this is stderr", + "something": "something", + "": ""} assert := assert.New(t) for log, expected := range logs {