summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLE Manh Cuong <cuong.manhle.vn@gmail.com>2015-11-13 11:57:21 +0700
committerLE Manh Cuong <cuong.manhle.vn@gmail.com>2015-11-13 20:17:58 +0700
commit8544b2f0f55a18a55cbc6db098ec70bc19f07246 (patch)
treeff27df62b1d30e646b59dcce2c0e4cf874f9b766
parentdc1ded469b4d0e790e2ba67cd8ea76caab9e91af (diff)
downloadstow-8544b2f0f55a18a55cbc6db098ec70bc19f07246.tar.gz
Allow directory with trailing and leading spaces
- The `sanitize_path_options` functions remove all trailing and leading spaces. So any valid directory like ` 123`, `123 ` can not be used - Also if there are two directories ` 123` and `123`, and if user pick the ` 123` as option to `-d` or `-t`, then stow pick directory `123` as the argument instead of ` 123` as user want. ``` STOW_DIR=. stow -n -v3 -t \ 123 456 stow dir is /tmp/test stow dir path relative to target 123 is .. cwd now 123 cwd restored to /tmp/test cwd now 123 Planning stow of package 456... Stowing contents of ../456 (cwd=/tmp/test/123) Planning stow of package 456... done cwd restored to /tmp/test WARNING: in simulation mode so not modifying filesystem. ``` - This commit remove the check in `sanitize_path_options` function, and now stow can work with those directories. There have been a check for valid directory, so we are safe.
-rwxr-xr-xbin/stow.in8
-rwxr-xr-xt/cli_options.t4
2 files changed, 3 insertions, 9 deletions
diff --git a/bin/stow.in b/bin/stow.in
index 1ebc695..ec83f59 100755
--- a/bin/stow.in
+++ b/bin/stow.in
@@ -537,11 +537,7 @@ sub process_options {
sub sanitize_path_options {
my ($options) = @_;
- if (exists $options->{dir}) {
- $options->{dir} =~ s/\A +//;
- $options->{dir} =~ s/ +\z//;
- }
- else {
+ unless (exists $options->{dir}) {
$options->{dir} = length $ENV{STOW_DIR} ? $ENV{STOW_DIR} : getcwd();
}
@@ -549,8 +545,6 @@ sub sanitize_path_options {
unless -d $options->{dir};
if (exists $options->{target}) {
- $options->{target} =~ s/\A +//;
- $options->{target} =~ s/ +\z//;
usage("--target value '$options->{target}' is not a valid directory")
unless -d $options->{target};
}
diff --git a/t/cli_options.t b/t/cli_options.t
index 809cf15..fafb6d8 100755
--- a/t/cli_options.t
+++ b/t/cli_options.t
@@ -17,8 +17,8 @@ init_test_dirs();
local @ARGV = (
'-v',
- "-d $OUT_DIR/stow",
- "-t $OUT_DIR/target",
+ '-d', "$OUT_DIR/stow",
+ '-t', "$OUT_DIR/target",
'dummy'
);