Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipfs-test-lib: fix test_fsh arg quoting #3085

Merged
merged 1 commit into from
Aug 16, 2016
Merged

ipfs-test-lib: fix test_fsh arg quoting #3085

merged 1 commit into from
Aug 16, 2016

Conversation

chriscool
Copy link
Contributor

@chriscool chriscool commented Aug 15, 2016

test_fsh() should quote its arguments before passing them
to eval otherwise there are problems when the arguments
contain spaces.

For example when running the following program:

#!/bin/sh

. ./ipfs-test-lib.sh

die () {
    printf >&2 "%s\n" "$@"
    exit 1
}

DIR1="test dir 1"
DIR2="test dir 2"

mkdir "$DIR1" "$DIR2" || die "Could not mkdir '$DIR1' '$DIR2'"

echo "in dir 1" >"$DIR1/file1" || die "Could not write into '$DIR1/file1'"
echo "in dir 2" >"$DIR2/file2" || die "Could not write into '$DIR2/file2'"

if test_cmp "$DIR1/file1" "$DIR2/file2"
then
    echo "test_cmp succeeded!"
else
    echo "test_cmp failed!"
fi

rm -rf "$DIR1" "$DIR2" || die "Could not rm -rf '$DIR1' '$DIR2'"

we get:

> diff -u test dir 1/file1 test dir 2/file2
diff: extra operand '1/file1'
diff: Try 'diff --help' for more information.

test_cmp failed!

License: MIT
Signed-off-by: Christian Couder chriscool@tuxfamily.org

@chriscool
Copy link
Contributor Author

@Kubuxu thanks for reporting this bug!

test_fsh() should quote its arguments before passing them
to `eval` otherwise there are problems when the arguments
contain spaces.

For example when running the following program:

```
#!/bin/sh

. ./ipfs-test-lib.sh

die () {
    printf >&2 "%s\n" "$@"
    exit 1
}

DIR1="test dir 1"
DIR2="test dir 2"

mkdir "$DIR1" "$DIR2" || die "Could not mkdir '$DIR1' '$DIR2'"

echo "in dir 1" >"$DIR1/file1" || die "Could not write into '$DIR1/file1'"
echo "in dir 2" >"$DIR2/file2" || die "Could not write into '$DIR2/file2'"

if test_cmp "$DIR1/file1" "$DIR2/file2"
then
    echo "test_cmp succeeded!"
else
    echo "test_cmp failed!"
fi

rm -rf "$DIR1" "$DIR2" || die "Could not rm -rf '$DIR1' '$DIR2'"

```

we get:

```
> diff -u test dir 1/file1 test dir 2/file2
diff: extra operand '1/file1'
diff: Try 'diff --help' for more information.

test_cmp failed!
```

License: MIT
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
@whyrusleeping
Copy link
Member

This LGTM, thanks @chriscool!

@whyrusleeping whyrusleeping merged commit 4eb7c6c into master Aug 16, 2016
@whyrusleeping whyrusleeping deleted the fix-test_fsh branch August 16, 2016 16:22
@ghost ghost mentioned this pull request Dec 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants