mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-12-31 20:01:52 +00:00
- Rewrite command line parsing code to support --opt val
- Add $php settings variable git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1555 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
8c439aa62c
commit
9f851b2139
@ -28,6 +28,7 @@ $GLOBALS['HTMLPurifierTest']['PH5P'] = class_exists('DOMDocument');
|
|||||||
$simpletest_location = 'simpletest/'; // reasonable guess
|
$simpletest_location = 'simpletest/'; // reasonable guess
|
||||||
$csstidy_location = false;
|
$csstidy_location = false;
|
||||||
$versions_to_test = array();
|
$versions_to_test = array();
|
||||||
|
$php = 'php';
|
||||||
$phpv = 'phpv';
|
$phpv = 'phpv';
|
||||||
|
|
||||||
// load configuration
|
// load configuration
|
||||||
@ -72,12 +73,8 @@ require_once 'tally_errors.func.php'; // compat
|
|||||||
* Arguments parser, is cli and web agnostic.
|
* Arguments parser, is cli and web agnostic.
|
||||||
* @warning
|
* @warning
|
||||||
* There are some quirks about the argument format:
|
* There are some quirks about the argument format:
|
||||||
* - Short flags cannot be chained together
|
* - Short boolean flags cannot be chained together
|
||||||
* - Any number of hyphens are allowed to lead flags
|
* - Only strings, integers and booleans are accepted
|
||||||
* - Flag values cannot have spaces in them
|
|
||||||
* - You must specify an equal sign, --foo=value; --foo value doesn't work
|
|
||||||
* - Only strings and booleans are accepted
|
|
||||||
* - This --flag=off will be interpreted as true, use --flag=0 instead
|
|
||||||
* @param $AC
|
* @param $AC
|
||||||
* Arguments array to populate. This takes a simple format of 'argument'
|
* Arguments array to populate. This takes a simple format of 'argument'
|
||||||
* => default value. Depending on the type of the default value,
|
* => default value. Depending on the type of the default value,
|
||||||
@ -90,15 +87,43 @@ require_once 'tally_errors.func.php'; // compat
|
|||||||
function htmlpurifier_parse_args(&$AC, $aliases) {
|
function htmlpurifier_parse_args(&$AC, $aliases) {
|
||||||
if (empty($_GET)) {
|
if (empty($_GET)) {
|
||||||
array_shift($_SERVER['argv']);
|
array_shift($_SERVER['argv']);
|
||||||
|
$o = false;
|
||||||
|
$bool = false;
|
||||||
|
$val_is_bool = false;
|
||||||
foreach ($_SERVER['argv'] as $opt) {
|
foreach ($_SERVER['argv'] as $opt) {
|
||||||
if (strpos($opt, "=") !== false) {
|
if ($o !== false) {
|
||||||
list($o, $v) = explode("=", $opt, 2);
|
$v = $opt;
|
||||||
} else {
|
} else {
|
||||||
$o = $opt;
|
if ($opt === '') continue;
|
||||||
$v = true;
|
if (strlen($opt) > 2 && strncmp($opt, '--', 2) === 0) {
|
||||||
|
$o = substr($opt, 2);
|
||||||
|
} elseif ($opt[0] == '-') {
|
||||||
|
$o = substr($opt, 1);
|
||||||
|
} else {
|
||||||
|
$lopt = strtolower($opt);
|
||||||
|
if ($bool !== false && ($opt === '0' || $lopt === 'off' || $lopt === 'no')) {
|
||||||
|
$o = $bool;
|
||||||
|
$v = false;
|
||||||
|
$val_is_bool = true;
|
||||||
|
} elseif (isset($aliases[''])) {
|
||||||
|
$o = $aliases[''];
|
||||||
}
|
}
|
||||||
$o = ltrim($o, '-');
|
}
|
||||||
|
$bool = false;
|
||||||
|
if (!isset($AC[$o]) || !is_bool($AC[$o])) {
|
||||||
|
if (strpos($o, '=') === false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
list($o, $v) = explode('=', $o);
|
||||||
|
} elseif (!$val_is_bool) {
|
||||||
|
$v = true;
|
||||||
|
$bool = $o;
|
||||||
|
}
|
||||||
|
$val_is_bool = false;
|
||||||
|
}
|
||||||
|
if ($o === false) continue;
|
||||||
htmlpurifier_args($AC, $aliases, $o, $v);
|
htmlpurifier_args($AC, $aliases, $o, $v);
|
||||||
|
$o = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foreach ($_GET as $o => $v) {
|
foreach ($_GET as $o => $v) {
|
||||||
@ -119,7 +144,8 @@ function htmlpurifier_args(&$AC, $aliases, $o, $v) {
|
|||||||
if (isset($aliases[$o])) $o = $aliases[$o];
|
if (isset($aliases[$o])) $o = $aliases[$o];
|
||||||
if (!isset($AC[$o])) return;
|
if (!isset($AC[$o])) return;
|
||||||
if (is_string($AC[$o])) $AC[$o] = $v;
|
if (is_string($AC[$o])) $AC[$o] = $v;
|
||||||
if (is_bool($AC[$o])) $AC[$o] = true;
|
if (is_bool($AC[$o])) $AC[$o] = (bool) $v;
|
||||||
|
if (is_int($AC[$o])) $AC[$o] = (int) $v;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,7 +39,7 @@ htmlpurifier_parse_args($AC, $aliases);
|
|||||||
|
|
||||||
if (!SimpleReporter::inCli()) {
|
if (!SimpleReporter::inCli()) {
|
||||||
// Undo any dangerous parameters
|
// Undo any dangerous parameters
|
||||||
$AC['php'] = 'php';
|
$AC['php'] = $php;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($AC['disable-phpt'] && $AC['only-phpt']) {
|
if ($AC['disable-phpt'] && $AC['only-phpt']) {
|
||||||
|
@ -98,7 +98,7 @@ foreach ($versions_to_test as $version) {
|
|||||||
//if (!$AC['disable-phpt']) {
|
//if (!$AC['disable-phpt']) {
|
||||||
$test->addTestCase(
|
$test->addTestCase(
|
||||||
new CliTestCase(
|
new CliTestCase(
|
||||||
$AC['php'] . " index.php --xml --php=\"$phpv $version\" --only-phpt",
|
$AC['php'] . " index.php --xml --php \"$phpv $version\" --only-phpt",
|
||||||
$AC['quiet'], $size
|
$AC['quiet'], $size
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user