-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sanitize some trace logs that might contain user input. #24
- Loading branch information
1 parent
b8b7f93
commit fa3955d
Showing
5 changed files
with
49 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package mars | ||
|
||
import "regexp" | ||
|
||
var lineBreakPattern = regexp.MustCompile(`[\r\n]+`) | ||
|
||
func removeLineBreaks(s string) string { | ||
return lineBreakPattern.ReplaceAllString(s, " ") | ||
} | ||
|
||
func removeAllWhitespace(s string) string { | ||
return whiteSpacePattern.ReplaceAllString(s, "") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package mars | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestRemovingLineBreaks(t *testing.T) { | ||
for i, exp := range map[string]string{ | ||
"This is a test.": "This is a test.", | ||
"This is\n a test.": "This is a test.", | ||
"This is\r a test.": "This is a test.", | ||
"This is\r\n a test.": "This is a test.", | ||
"\n\n\n\n\nThis is\r a test.": " This is a test.", | ||
} { | ||
if res := removeLineBreaks(i); res != exp { | ||
t.Errorf("Unexpected result '%s' when removing line breaks from '%s'.\n", res, i) | ||
} | ||
} | ||
} | ||
|
||
func TestRemovingAllWhitespace(t *testing.T) { | ||
for i, exp := range map[string]string{ | ||
"This is a test.": "Thisisatest.", | ||
"This is\n a test.": "Thisisatest.", | ||
"This is\r a test.": "Thisisatest.", | ||
"This is\r\n a test.": "Thisisatest.", | ||
"\n\n\n\n\nThis is\r a test.": "Thisisatest.", | ||
} { | ||
if res := removeAllWhitespace(i); res != exp { | ||
t.Errorf("Unexpected result '%s' when removing all whitespace from '%s'.\n", res, i) | ||
} | ||
} | ||
} |