Promote warnings to exceptions in ext/tidy

Closes GH-6051
This commit is contained in:
Máté Kocsis 2020-08-28 10:27:40 +02:00
parent a99d08b5d1
commit 7476d2c188
No known key found for this signature in database
GPG Key ID: FD055E41728BF310
6 changed files with 62 additions and 52 deletions

View File

@ -6,24 +6,30 @@ Verbose tidy_getopt()
tidy.default_config=
--FILE--
<?php
$a = new tidy(__DIR__."/007.html");
echo "Current Value of 'tidy-mark': ";
var_dump($a->getopt("tidy-mark"));
echo "Current Value of 'error-file': ";
var_dump($a->getopt("error-file"));
echo "Current Value of 'tab-size': ";
var_dump($a->getopt("tab-size"));
$a = new tidy(__DIR__."/007.html");
echo "Current Value of 'tidy-mark': ";
var_dump($a->getopt("tidy-mark"));
echo "Current Value of 'error-file': ";
var_dump($a->getopt("error-file"));
echo "Current Value of 'tab-size': ";
var_dump($a->getopt("tab-size"));
try {
$a->getopt('bogus-opt');
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
try {
tidy_getopt($a, 'non-ASCII string <20><><EFBFBD>');
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
var_dump($a->getopt('bogus-opt'));
var_dump(tidy_getopt($a, 'non-ASCII string àáç'));
?>
--EXPECTF--
Current Value of 'tidy-mark': bool(false)
Current Value of 'error-file': string(0) ""
Current Value of 'tab-size': int(8)
Warning: tidy::getOpt(): Unknown Tidy Configuration Option 'bogus-opt' in %s007.php on line 10
bool(false)
Warning: tidy_getopt(): Unknown Tidy Configuration Option 'non-ASCII string àáç' in %s007.php on line 11
bool(false)
tidy::getOpt(): Argument #1 ($option) is an invalid configuration option, "bogus-opt" given
tidy_getopt(): Argument #2 ($option) is an invalid configuration option, "non-ASCII string <20><><EFBFBD>" given

View File

@ -28,15 +28,15 @@ tidy_repair_file($l, $l, $l ,$l); // This doesn't emit any warning, TODO look in
echo "Done\n";
?>
--EXPECTF--
Warning: tidy_repair_string(): Could not load configuration file '1' in %s on line %d
Warning: tidy_repair_string(): Could not load configuration file "1" in %s on line %d
Warning: tidy_repair_string(): Could not set encoding '1' in %s on line %d
Warning: tidy_repair_string(): Could not set encoding "1" in %s on line %d
Warning: tidy_repair_string(): Could not load configuration file '' in %s on line %d
Warning: tidy_repair_string(): Could not load configuration file "" in %s on line %d
Warning: tidy_repair_string(): Could not load configuration file '1' in %s on line %d
Warning: tidy_repair_string(): Could not load configuration file "1" in %s on line %d
Warning: tidy_repair_string(): Could not set encoding '1' in %s on line %d
Warning: tidy_repair_string(): Could not set encoding "1" in %s on line %d
Path cannot be empty
Path cannot be empty
Done

View File

@ -5,14 +5,17 @@ tidy_get_opt_doc()
--FILE--
<?php
var_dump(tidy_get_opt_doc(new tidy, 'some_bogus_cfg'));
try {
tidy_get_opt_doc(new tidy, 'some_bogus_cfg');
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
$t = new tidy;
var_dump($t->getOptDoc('ncr'));
var_dump(strlen(tidy_get_opt_doc($t, 'wrap')) > 99);
?>
--EXPECTF--
Warning: tidy_get_opt_doc(): Unknown Tidy Configuration Option 'some_bogus_cfg' in %s021.php on line 3
bool(false)
--EXPECT--
tidy_get_opt_doc(): Argument #2 ($optname) is an invalid configuration option, "some_bogus_cfg" given
string(73) "This option specifies if Tidy should allow numeric character references. "
bool(true)

View File

@ -10,4 +10,4 @@ $nx->diagnose();
?>
--EXPECTF--
Warning: tidy::__construct(): Cannot Load '*' into memory%win %s on line %d
Warning: tidy::__construct(): Cannot load "*" into memory%win %s on line %d

View File

@ -13,7 +13,8 @@ $config = array('bogus' => 'willnotwork');
$tidy = new tidy();
var_dump($tidy->parseString($buffer, $config));
?>
--EXPECTF--
Notice: tidy::parseString(): Unknown Tidy Configuration Option 'bogus' in %s on line %d
Warning: tidy::parseString(): Unknown Tidy configuration option "bogus" in %s on line %d
bool(true)

View File

@ -76,10 +76,10 @@
TIDY_OPEN_BASE_DIR_CHECK(Z_STRVAL_P(_val)); \
switch (tidyLoadConfig(_doc, Z_STRVAL_P(_val))) { \
case -1: \
php_error_docref(NULL, E_WARNING, "Could not load configuration file '%s'", Z_STRVAL_P(_val)); \
php_error_docref(NULL, E_WARNING, "Could not load configuration file \"%s\"", Z_STRVAL_P(_val)); \
break; \
case 1: \
php_error_docref(NULL, E_NOTICE, "There were errors while parsing the configuration file '%s'", Z_STRVAL_P(_val)); \
php_error_docref(NULL, E_NOTICE, "There were errors while parsing the configuration file \"%s\"", Z_STRVAL_P(_val)); \
break; \
} \
} \
@ -158,7 +158,7 @@ if (php_check_open_basedir(filename)) { \
#define TIDY_SET_DEFAULT_CONFIG(_doc) \
if (TG(default_config) && TG(default_config)[0]) { \
if (tidyLoadConfig(_doc, TG(default_config)) < 0) { \
php_error_docref(NULL, E_WARNING, "Unable to load Tidy configuration file at '%s'.", TG(default_config)); \
php_error_docref(NULL, E_WARNING, "Unable to load Tidy configuration file at \"%s\"", TG(default_config)); \
} \
}
/* }}} */
@ -289,12 +289,12 @@ static int _php_tidy_set_tidy_opt(TidyDoc doc, char *optname, zval *value)
zend_long lval;
if (!opt) {
php_error_docref(NULL, E_NOTICE, "Unknown Tidy Configuration Option '%s'", optname);
php_error_docref(NULL, E_WARNING, "Unknown Tidy configuration option \"%s\"", optname);
return FAILURE;
}
if (tidyOptIsReadOnly(opt)) {
php_error_docref(NULL, E_NOTICE, "Attempting to set read-only option '%s'", optname);
php_error_docref(NULL, E_WARNING, "Attempting to set read-only option \"%s\"", optname);
return FAILURE;
}
@ -356,8 +356,8 @@ static void php_tidy_quick_repair(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_fil
}
if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(data))) {
php_error_docref(NULL, E_WARNING, "Input string is too long");
RETURN_FALSE;
zend_argument_value_error(1, "is too long");
RETURN_THROWS();
}
doc = tidyCreate();
@ -382,7 +382,7 @@ static void php_tidy_quick_repair(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_fil
if(enc_len) {
if (tidySetCharEncoding(doc, enc) < 0) {
php_error_docref(NULL, E_WARNING, "Could not set encoding '%s'", enc);
php_error_docref(NULL, E_WARNING, "Could not set encoding \"%s\"", enc);
RETVAL_FALSE;
}
}
@ -798,7 +798,7 @@ static int php_tidy_parse_string(PHPTidyObj *obj, char *string, uint32_t len, ch
if(enc) {
if (tidySetCharEncoding(obj->ptdoc->doc, enc) < 0) {
php_error_docref(NULL, E_WARNING, "Could not set encoding '%s'", enc);
php_error_docref(NULL, E_WARNING, "Could not set encoding \"%s\"", enc);
return FAILURE;
}
}
@ -995,8 +995,8 @@ PHP_FUNCTION(tidy_parse_string)
}
if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(input))) {
php_error_docref(NULL, E_WARNING, "Input string is too long");
RETURN_FALSE;
zend_argument_value_error(1, "is too long");
RETURN_THROWS();
}
tidy_instanciate(tidy_ce_doc, return_value);
@ -1058,13 +1058,13 @@ PHP_FUNCTION(tidy_parse_file)
obj = Z_TIDY_P(return_value);
if (!(contents = php_tidy_file_to_mem(ZSTR_VAL(inputfile), use_include_path))) {
php_error_docref(NULL, E_WARNING, "Cannot Load '%s' into memory%s", ZSTR_VAL(inputfile), (use_include_path) ? " (Using include path)" : "");
php_error_docref(NULL, E_WARNING, "Cannot load \"%s\" into memory%s", ZSTR_VAL(inputfile), (use_include_path) ? " (using include path)" : "");
RETURN_FALSE;
}
if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(contents))) {
php_error_docref(NULL, E_WARNING, "Input string is too long");
RETURN_FALSE;
zend_value_error("Input string is too long");
RETURN_THROWS();
}
TIDY_APPLY_CONFIG_ZVAL(obj->ptdoc->doc, options);
@ -1155,8 +1155,8 @@ PHP_FUNCTION(tidy_get_opt_doc)
opt = tidyGetOptionByName(obj->ptdoc->doc, optname);
if (!opt) {
php_error_docref(NULL, E_WARNING, "Unknown Tidy Configuration Option '%s'", optname);
RETURN_FALSE;
zend_argument_value_error(getThis() ? 1 : 2, "is an invalid configuration option, \"%s\" given", optname);
RETURN_THROWS();
}
if ( (optval = (char *) tidyOptGetDoc(obj->ptdoc->doc, opt)) ) {
@ -1299,8 +1299,8 @@ PHP_FUNCTION(tidy_getopt)
opt = tidyGetOptionByName(obj->ptdoc->doc, optname);
if (!opt) {
php_error_docref(NULL, E_WARNING, "Unknown Tidy Configuration Option '%s'", optname);
RETURN_FALSE;
zend_argument_value_error(getThis() ? 1 : 2, "is an invalid configuration option, \"%s\" given", optname);
RETURN_THROWS();
}
optval = php_tidy_get_opt_val(obj->ptdoc, opt, &optt);
@ -1350,13 +1350,13 @@ PHP_METHOD(tidy, __construct)
if (inputfile) {
if (!(contents = php_tidy_file_to_mem(ZSTR_VAL(inputfile), use_include_path))) {
php_error_docref(NULL, E_WARNING, "Cannot Load '%s' into memory%s", ZSTR_VAL(inputfile), (use_include_path) ? " (Using include path)" : "");
php_error_docref(NULL, E_WARNING, "Cannot load \"%s\" into memory%s", ZSTR_VAL(inputfile), (use_include_path) ? " (using include path)" : "");
return;
}
if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(contents))) {
php_error_docref(NULL, E_WARNING, "Input string is too long");
RETURN_FALSE;
zend_value_error("Input string is too long");
RETURN_THROWS();
}
TIDY_APPLY_CONFIG_ZVAL(obj->ptdoc->doc, options);
@ -1386,13 +1386,13 @@ PHP_METHOD(tidy, parseFile)
}
if (!(contents = php_tidy_file_to_mem(ZSTR_VAL(inputfile), use_include_path))) {
php_error_docref(NULL, E_WARNING, "Cannot Load '%s' into memory%s", ZSTR_VAL(inputfile), (use_include_path) ? " (Using include path)" : "");
php_error_docref(NULL, E_WARNING, "Cannot load \"%s\" into memory%s", ZSTR_VAL(inputfile), (use_include_path) ? " (using include path)" : "");
RETURN_FALSE;
}
if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(contents))) {
php_error_docref(NULL, E_WARNING, "Input string is too long");
RETURN_FALSE;
zend_value_error("Input string is too long");
RETURN_THROWS();
}
TIDY_APPLY_CONFIG_ZVAL(obj->ptdoc->doc, options);
@ -1421,8 +1421,8 @@ PHP_METHOD(tidy, parseString)
}
if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(input))) {
php_error_docref(NULL, E_WARNING, "Input string is too long");
RETURN_FALSE;
zend_argument_value_error(1, "is too long");
RETURN_THROWS();
}
obj = Z_TIDY_P(object);