aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--cli_args.go10
-rw-r--r--cli_args_test.go10
3 files changed, 20 insertions, 1 deletions
diff --git a/README.md b/README.md
index 5e6d1e7..a37cb63 100644
--- a/README.md
+++ b/README.md
@@ -162,6 +162,7 @@ v1.3 (in progress)
* Use stable 64-bit inode numbers in reverse mode
* This may cause problems for very old 32-bit applications
that were compiled without Large File Support.
+* Passing "--" now also block "-o" parsing
v1.2.1, 2017-02-26
* Add an integrated speed test, `gocryptfs -speed`
diff --git a/cli_args.go b/cli_args.go
index e42d9ae..e8fab75 100644
--- a/cli_args.go
+++ b/cli_args.go
@@ -36,11 +36,19 @@ var flagSet *flag.FlagSet
// prefixOArgs transform options passed via "-o foo,bar" into regular options
// like "-foo -bar" and prefixes them to the command line.
+// Testcases in TestPrefixOArgs().
func prefixOArgs(osArgs []string) []string {
- // Need at least 3, example: gocryptfs -o foo,bar
+ // Need at least 3, example: gocryptfs -o foo,bar
+ // ^ 0 ^ 1 ^ 2
if len(osArgs) < 3 {
return osArgs
}
+ // Passing "--" disables "-o" parsing. Ignore element 0 (program name).
+ for _, v := range osArgs[1:] {
+ if v == "--" {
+ return osArgs
+ }
+ }
// Find and extract "-o foo,bar"
var otherArgs, oOpts []string
for i := 1; i < len(osArgs); i++ {
diff --git a/cli_args_test.go b/cli_args_test.go
index 8846491..63a33ef 100644
--- a/cli_args_test.go
+++ b/cli_args_test.go
@@ -12,6 +12,7 @@ type testcase struct {
o []string
}
+// TestPrefixOArgs checks that the "-o x,y,z" parsing works correctly.
func TestPrefixOArgs(t *testing.T) {
testcases := []testcase{
{
@@ -51,6 +52,15 @@ func TestPrefixOArgs(t *testing.T) {
i: []string{"gocryptfs", "-o", "rw", "--config", "fff", "ccc", "mmm"},
o: []string{"gocryptfs", "-rw", "--config", "fff", "ccc", "mmm"},
},
+ // "--" should also block "-o" parsing.
+ {
+ i: []string{"gocryptfs", "foo", "bar", "--", "-o", "a"},
+ o: []string{"gocryptfs", "foo", "bar", "--", "-o", "a"},
+ },
+ {
+ i: []string{"gocryptfs", "--", "-o", "a"},
+ o: []string{"gocryptfs", "--", "-o", "a"},
+ },
}
for _, tc := range testcases {
o := prefixOArgs(tc.i)