Skip to content

Commit

Permalink
Merge pull request #259 from asottile/improve_quoting
Browse files Browse the repository at this point in the history
Improve quoting of varibles in the node shim for -n system
  • Loading branch information
ekalinin authored Jun 2, 2020
2 parents c7edf71 + 5e757ff commit 92ac5f3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
8 changes: 4 additions & 4 deletions nodeenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,10 +1074,10 @@ def main():
}

SHIM = """#!/usr/bin/env bash
export NODE_PATH=__NODE_VIRTUAL_ENV__/lib/node_modules
export NPM_CONFIG_PREFIX=__NODE_VIRTUAL_ENV__
export npm_config_prefix=__NODE_VIRTUAL_ENV__
exec __SHIM_NODE__ "$@"
export NODE_PATH='__NODE_VIRTUAL_ENV__/lib/node_modules'
export NPM_CONFIG_PREFIX='__NODE_VIRTUAL_ENV__'
export npm_config_prefix='__NODE_VIRTUAL_ENV__'
exec '__SHIM_NODE__' "$@"
"""

ACTIVATE_BAT = r"""
Expand Down
19 changes: 18 additions & 1 deletion tests/nodeenv_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

import os.path
import pipes
import subprocess
import sys

Expand All @@ -23,8 +24,24 @@ def test_smoke(tmpdir):
'-m', 'nodeenv', '--prebuilt', nenv_path,
])
assert os.path.exists(nenv_path)
activate = pipes.quote(os.path.join(nenv_path, 'bin', 'activate'))
subprocess.check_call([
'sh', '-c', '. {0}/bin/activate && nodejs --version'.format(nenv_path),
'sh', '-c', '. {} && nodejs --version'.format(activate),
])


@pytest.mark.integration
@pytest.mark.skipif(sys.platform == 'win32', reason='-n system is posix only')
def test_smoke_n_system_special_chars(tmpdir):
nenv_path = tmpdir.join('nenv (production env)').strpath
subprocess.check_call((
'coverage', 'run', '-p',
'-m', 'nodeenv', '-n', 'system', nenv_path,
))
assert os.path.exists(nenv_path)
activate = pipes.quote(os.path.join(nenv_path, 'bin', 'activate'))
subprocess.check_call([
'sh', '-c', '. {} && nodejs --version'.format(activate),
])


Expand Down
4 changes: 4 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ deps =
sphinx
changedir = docs
commands = sphinx-build -b html -d build/doctrees source build/html

[pytest]
markers =
integration: tests that take a little bit longer

0 comments on commit 92ac5f3

Please sign in to comment.