Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/XCLogParser/lexer/LexRedactor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class LexRedactor: LogRedactor {
private static let redactedTemplate = "/Users/<redacted>/"
private lazy var userDirRegex: NSRegularExpression? = {
do {
return try NSRegularExpression(pattern: "\\/Users\\/(\\w*)\\/")
return try NSRegularExpression(pattern: "/Users/([^/]+)/?")
} catch {
return nil
}
Expand Down
14 changes: 12 additions & 2 deletions Tests/XCLogParserTests/LexRedactorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,24 @@ class LexRedactorTests: XCTestCase {
let redactor = LexRedactor()

func testRedacting() {

let redactedText = redactor.redactUserDir(string: "Some /Users/private/path")

XCTAssertEqual(redactedText, "Some /Users/<redacted>/path")
}

func testMultiplePathsRedacting() {
func testRedactingComplexUsername() {
let redactedText = redactor.redactUserDir(string: "Some /Users/private-user/path")

XCTAssertEqual(redactedText, "Some /Users/<redacted>/path")
}

func testRedactingHomePath() {
let redactedText = redactor.redactUserDir(string: "/Users/private-user")

XCTAssertEqual(redactedText, "/Users/<redacted>/")
}

func testMultiplePathsRedacting() {
let redactedText = redactor.redactUserDir(string: "Some /Users/private/path and other /Users/private/path2")

XCTAssertEqual(redactedText, "Some /Users/<redacted>/path and other /Users/<redacted>/path2")
Expand Down