Skip to content

Commit 71b5e6d

Browse files
committed
quote the path as we are editing the pth file; fixes #132
1 parent 16bdb77 commit 71b5e6d

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

docs/en/history.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ dev
66

77
- Fix a problem with activation hooks when associating a new
88
virtualenv with an existing project directory. (:bbissue:`122`)
9+
- Fix a problem with :ref:`command-add2virtualenv` and paths
10+
containing "special" characters such as ``&``. (:bbissue:`132`)
911

1012
3.0.1
1113

tests/test_add2virtualenv.sh

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export WORKON_HOME="$(echo ${TMPDIR:-/tmp}/WORKON_HOME | sed 's|//|/|g')"
99
oneTimeSetUp() {
1010
rm -rf "$WORKON_HOME"
1111
mkdir -p "$WORKON_HOME"
12-
source "$test_dir/../virtualenvwrapper.sh"
12+
source "$test_dir/../virtualenvwrapper.sh" >/dev/null 2>&1
1313
}
1414

1515
oneTimeTearDown() {
@@ -41,7 +41,7 @@ test_add2virtualenv () {
4141
}
4242

4343
test_add2virtualenv_relative () {
44-
mkvirtualenv "pathtest" >/dev/null 2>&1
44+
mkvirtualenv "pathtest_relative" >/dev/null 2>&1
4545
parent_dir=$(dirname $(pwd))
4646
base_dir=$(basename $(pwd))
4747
add2virtualenv "../$base_dir"
@@ -51,18 +51,70 @@ test_add2virtualenv_relative () {
5151
cd - >/dev/null 2>&1
5252
}
5353

54+
test_add2virtualenv_space () {
55+
# see #132
56+
mkvirtualenv "pathtest_space" >/dev/null 2>&1
57+
parent_dir=$(dirname $(pwd))
58+
cdvirtualenv
59+
mkdir 'a b'
60+
add2virtualenv 'a b'
61+
cdsitepackages
62+
path_file="./_virtualenv_path_extensions.pth"
63+
assertTrue "No 'a b' in \"`cat $path_file`\"" "grep -q 'a b' $path_file"
64+
cd - >/dev/null 2>&1
65+
}
66+
67+
test_add2virtualenv_ampersand () {
68+
# see #132
69+
mkvirtualenv "pathtest_ampersand" >/dev/null 2>&1
70+
parent_dir=$(dirname $(pwd))
71+
cdvirtualenv
72+
mkdir 'a & b'
73+
add2virtualenv 'a & b'
74+
cdsitepackages
75+
path_file="./_virtualenv_path_extensions.pth"
76+
assertTrue "No 'a & b' in \"`cat $path_file`\"" "grep -q 'a & b' $path_file"
77+
cd - >/dev/null 2>&1
78+
}
79+
5480
test_add2virtualenv_delete () {
5581
path_file="./_virtualenv_path_extensions.pth"
56-
mkvirtualenv "pathtest" >/dev/null 2>&1
82+
mkvirtualenv "pathtest_delete" >/dev/null 2>&1
5783
cdsitepackages
5884
# Make sure it was added
5985
add2virtualenv "/full/path"
60-
assertTrue "No $full_path in $(cat $path_file)" "grep -q $full_path $path_file"
86+
assertTrue "No /full/path in $(cat $path_file)" "grep -q /full/path $path_file"
6187
# Remove it and verify that change
6288
add2virtualenv -d "/full/path"
6389
assertFalse "/full/path in `cat $path_file`" "grep -q /full/path $path_file"
6490
cd - >/dev/null 2>&1
6591
}
6692

93+
test_add2virtualenv_delete_space () {
94+
path_file="./_virtualenv_path_extensions.pth"
95+
mkvirtualenv "pathtest_delete_space" >/dev/null 2>&1
96+
cdsitepackages
97+
# Make sure it was added
98+
add2virtualenv "/full/path with spaces"
99+
assertTrue "No /full/path with spaces in $(cat $path_file)" "grep -q '/full/path with spaces' $path_file"
100+
# Remove it and verify that change
101+
add2virtualenv -d "/full/path with spaces"
102+
assertFalse "/full/path with spaces in `cat $path_file`" "grep -q '/full/path with spaces' $path_file"
103+
cd - >/dev/null 2>&1
104+
}
105+
106+
test_add2virtualenv_delete_ampersand () {
107+
path_file="./_virtualenv_path_extensions.pth"
108+
mkvirtualenv "pathtest_delete_ampersand" >/dev/null 2>&1
109+
cdsitepackages
110+
# Make sure it was added
111+
add2virtualenv "/full/path & dir"
112+
assertTrue "No /full/path & dir in $(cat $path_file)" "grep -q '/full/path & dir' $path_file"
113+
# Remove it and verify that change
114+
add2virtualenv -d "/full/path & dir"
115+
assertFalse "/full/path & dir in `cat $path_file`" "grep -q '/full/path & dir' $path_file"
116+
cd - >/dev/null 2>&1
117+
}
118+
67119

68120
. "$test_dir/shunit2"

virtualenvwrapper.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ function add2virtualenv {
671671
sed -i.tmp "\:^$absolute_path$: d" "$path_file"
672672
else
673673
sed -i.tmp '1 a\
674-
'$absolute_path'
674+
'"$absolute_path"'
675675
' "$path_file"
676676
fi
677677
rm -f "${path_file}.tmp"

0 commit comments

Comments
 (0)