Skip to content

Commit 7fe920d

Browse files
committed
Actually escape whitespace characters instead of quoting the entire string
1 parent ad81078 commit 7fe920d

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

Sources/Task.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ public struct Task {
4747
}
4848

4949
private extension String {
50+
static let whitespaceRegularExpression = try! NSRegularExpression(pattern: "\\s")
51+
5052
var escaped: String {
51-
if rangeOfCharacter(from: .whitespaces) != nil {
52-
return "\"\(self)\""
53-
} else {
54-
return self
55-
}
53+
return String.whitespaceRegularExpression.stringByReplacingMatches(
54+
in: self,
55+
range: NSRange(location: 0, length: self.utf16.count),
56+
withTemplate: "\\\\$0"
57+
)
5658
}
5759
}
5860

0 commit comments

Comments
 (0)