aboutsummaryrefslogtreecommitdiff
path: root/filesystem/mountpoint_test.go
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2022-02-23 12:35:04 -0800
committerEric Biggers <ebiggers@google.com>2022-02-23 12:35:04 -0800
commitbd380777d68816b55da85a42d4cdf7fb262b4ba2 (patch)
treea53418f4b71b351193fc0a24e2b9cd039b6424df /filesystem/mountpoint_test.go
parent1ab74f59b52ec244fee003effa8415c6c4038a54 (diff)
Make the output of 'fscrypt status' unambiguous
Following the example of /proc/self/mountinfo, replace the space, newline, tab, and backslash characters with octal escape sequences so that the output can be parsed unambiguously.
Diffstat (limited to 'filesystem/mountpoint_test.go')
-rw-r--r--filesystem/mountpoint_test.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/filesystem/mountpoint_test.go b/filesystem/mountpoint_test.go
index 749e5e3..99d4b55 100644
--- a/filesystem/mountpoint_test.go
+++ b/filesystem/mountpoint_test.go
@@ -179,6 +179,21 @@ func TestLoadMountWithSpecialCharacters(t *testing.T) {
}
}
+// Tests the EscapeString() and unescapeString() functions.
+func TestStringEscaping(t *testing.T) {
+ charsNeedEscaping := " \t\n\\"
+ charsDontNeedEscaping := "ABCDEF\u2603\xff\xff\v"
+
+ orig := charsNeedEscaping + charsDontNeedEscaping
+ escaped := `\040\011\012\134` + charsDontNeedEscaping
+ if EscapeString(orig) != escaped {
+ t.Fatal("EscapeString gave wrong result")
+ }
+ if unescapeString(escaped) != orig {
+ t.Fatal("unescapeString gave wrong result")
+ }
+}
+
// Test parsing some invalid mountinfo lines.
func TestLoadBadMountInfo(t *testing.T) {
mountinfos := []string{"a",