Commit 0420fe31 authored by Jérome Perrin's avatar Jérome Perrin

apachedex: fix argument parsing

Use shlex from standard library which splits arguments properly instead of
implementing our own buggy version.
parent 840e40bb
...@@ -32,7 +32,7 @@ from __future__ import print_function ...@@ -32,7 +32,7 @@ from __future__ import print_function
import os, errno import os, errno
import subprocess import subprocess
import argparse import argparse
import time import shlex
from datetime import date from datetime import date
# run_apachedex.py <apachedex_executable> /srv/etc/output_folder script_name # run_apachedex.py <apachedex_executable> /srv/etc/output_folder script_name
...@@ -61,8 +61,7 @@ def build_command(apachedex_executable, output_file, ...@@ -61,8 +61,7 @@ def build_command(apachedex_executable, output_file,
raise ValueError("log_list: no log files to analyse were provided") raise ValueError("log_list: no log files to analyse were provided")
if config: if config:
config = filter(None, [x.strip() for x in config.split(' ')]) argument_list.extend(shlex.split(config))
argument_list += config
argument_list.append('--error-detail') argument_list.append('--error-detail')
argument_list += log_list argument_list += log_list
......
...@@ -64,6 +64,19 @@ class TestApachedexCommand(unittest.TestCase): ...@@ -64,6 +64,19 @@ class TestApachedexCommand(unittest.TestCase):
'--base', 'bar', 'foo', '--base', 'bar', 'foo',
'--default', 'foo', '--default', 'foo',
'--error-detail', self.acesslog1, self.acesslog2 ]) '--error-detail', self.acesslog1, self.acesslog2 ])
def test_complexCommandEscape(self):
command = build_command(self.apachedex,
'bar.html',
[self.acesslog1, self.acesslog2],
'--base "foo bar"')
self.assertEqual(command, ['/bin/apachedex',
'--js-embed',
'--out', 'bar.html',
'--base', 'foo bar',
'--error-detail', self.acesslog1, self.acesslog2 ])
def test_raiseErro(self): def test_raiseErro(self):
self.assertRaises(ValueError, build_command, self.apachedex, 'foo.html', []) self.assertRaises(ValueError, build_command, self.apachedex, 'foo.html', [])
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment