Skip to content

Commit 74188b0

Browse files
committed
Promote warnings to exceptions in ext/tidy
1 parent 972041d commit 74188b0

File tree

6 files changed

+61
-51
lines changed

6 files changed

+61
-51
lines changed

ext/tidy/tests/007.phpt

+21-15
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,30 @@ Verbose tidy_getopt()
66
tidy.default_config=
77
--FILE--
88
<?php
9-
$a = new tidy(__DIR__."/007.html");
10-
echo "Current Value of 'tidy-mark': ";
11-
var_dump($a->getopt("tidy-mark"));
12-
echo "Current Value of 'error-file': ";
13-
var_dump($a->getopt("error-file"));
14-
echo "Current Value of 'tab-size': ";
15-
var_dump($a->getopt("tab-size"));
9+
$a = new tidy(__DIR__."/007.html");
10+
echo "Current Value of 'tidy-mark': ";
11+
var_dump($a->getopt("tidy-mark"));
12+
echo "Current Value of 'error-file': ";
13+
var_dump($a->getopt("error-file"));
14+
echo "Current Value of 'tab-size': ";
15+
var_dump($a->getopt("tab-size"));
16+
17+
try {
18+
$a->getopt('bogus-opt');
19+
} catch (ValueError $exception) {
20+
echo $exception->getMessage() . "\n";
21+
}
22+
23+
try {
24+
tidy_getopt($a, 'non-ASCII string ���');
25+
} catch (ValueError $exception) {
26+
echo $exception->getMessage() . "\n";
27+
}
1628

17-
var_dump($a->getopt('bogus-opt'));
18-
var_dump(tidy_getopt($a, 'non-ASCII string àáç'));
1929
?>
2030
--EXPECTF--
2131
Current Value of 'tidy-mark': bool(false)
2232
Current Value of 'error-file': string(0) ""
2333
Current Value of 'tab-size': int(8)
24-
25-
Warning: tidy::getOpt(): Unknown Tidy Configuration Option 'bogus-opt' in %s007.php on line 10
26-
bool(false)
27-
28-
Warning: tidy_getopt(): Unknown Tidy Configuration Option 'non-ASCII string àáç' in %s007.php on line 11
29-
bool(false)
34+
tidy::getOpt(): Argument #2 is an invalid configuration option
35+
tidy_getopt(): Argument #2 ($option) is an invalid configuration option

ext/tidy/tests/019.phpt

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ tidy_repair_file($l, $l, $l ,$l); // This doesn't emit any warning, TODO look in
2828
echo "Done\n";
2929
?>
3030
--EXPECTF--
31-
Warning: tidy_repair_string(): Could not load configuration file '1' in %s on line %d
31+
Warning: tidy_repair_string(): Could not load configuration file "1" in %s on line %d
3232

33-
Warning: tidy_repair_string(): Could not set encoding '1' in %s on line %d
33+
Warning: tidy_repair_string(): Could not set encoding "1" in %s on line %d
3434

35-
Warning: tidy_repair_string(): Could not load configuration file '' in %s on line %d
35+
Warning: tidy_repair_string(): Could not load configuration file "" in %s on line %d
3636

37-
Warning: tidy_repair_string(): Could not load configuration file '1' in %s on line %d
37+
Warning: tidy_repair_string(): Could not load configuration file "1" in %s on line %d
3838

39-
Warning: tidy_repair_string(): Could not set encoding '1' in %s on line %d
39+
Warning: tidy_repair_string(): Could not set encoding "1" in %s on line %d
4040
Path cannot be empty
4141
Path cannot be empty
4242
Done

ext/tidy/tests/021.phpt

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ tidy_get_opt_doc()
55
--FILE--
66
<?php
77

8-
var_dump(tidy_get_opt_doc(new tidy, 'some_bogus_cfg'));
8+
try {
9+
tidy_get_opt_doc(new tidy, 'some_bogus_cfg');
10+
} catch (ValueError $exception) {
11+
echo $exception->getMessage() . "\n";
12+
}
913

1014
$t = new tidy;
1115
var_dump($t->getOptDoc('ncr'));
1216
var_dump(strlen(tidy_get_opt_doc($t, 'wrap')) > 99);
1317
?>
1418
--EXPECTF--
15-
Warning: tidy_get_opt_doc(): Unknown Tidy Configuration Option 'some_bogus_cfg' in %s021.php on line 3
16-
bool(false)
19+
tidy_get_opt_doc(): Argument #2 ($optname) is an invalid configuration option
1720
string(73) "This option specifies if Tidy should allow numeric character references. "
1821
bool(true)

ext/tidy/tests/bug54682.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ $nx->diagnose();
1010

1111
?>
1212
--EXPECTF--
13-
Warning: tidy::__construct(): Cannot Load '*' into memory%win %s on line %d
13+
Warning: tidy::__construct(): Cannot load "*" into memory%win %s on line %d

ext/tidy/tests/tidy_error1.phpt

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ $config = array('bogus' => 'willnotwork');
1313

1414
$tidy = new tidy();
1515
var_dump($tidy->parseString($buffer, $config));
16+
1617
?>
1718
--EXPECTF--
18-
Notice: tidy::parseString(): Unknown Tidy Configuration Option 'bogus' in %s on line %d
19+
Warning: tidy::parseString(): Unknown Tidy configuration option "bogus" in %s on line %d
1920
bool(true)

ext/tidy/tidy.c

+26-26
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@
7676
TIDY_OPEN_BASE_DIR_CHECK(Z_STRVAL_P(_val)); \
7777
switch (tidyLoadConfig(_doc, Z_STRVAL_P(_val))) { \
7878
case -1: \
79-
php_error_docref(NULL, E_WARNING, "Could not load configuration file '%s'", Z_STRVAL_P(_val)); \
79+
php_error_docref(NULL, E_WARNING, "Could not load configuration file \"%s\"", Z_STRVAL_P(_val)); \
8080
break; \
8181
case 1: \
82-
php_error_docref(NULL, E_NOTICE, "There were errors while parsing the configuration file '%s'", Z_STRVAL_P(_val)); \
82+
php_error_docref(NULL, E_NOTICE, "There were errors while parsing the configuration file \"%s\"", Z_STRVAL_P(_val)); \
8383
break; \
8484
} \
8585
} \
@@ -158,7 +158,7 @@ if (php_check_open_basedir(filename)) { \
158158
#define TIDY_SET_DEFAULT_CONFIG(_doc) \
159159
if (TG(default_config) && TG(default_config)[0]) { \
160160
if (tidyLoadConfig(_doc, TG(default_config)) < 0) { \
161-
php_error_docref(NULL, E_WARNING, "Unable to load Tidy configuration file at '%s'.", TG(default_config)); \
161+
php_error_docref(NULL, E_WARNING, "Unable to load Tidy configuration file at \"%s\"", TG(default_config)); \
162162
} \
163163
}
164164
/* }}} */
@@ -289,12 +289,12 @@ static int _php_tidy_set_tidy_opt(TidyDoc doc, char *optname, zval *value)
289289
zend_long lval;
290290

291291
if (!opt) {
292-
php_error_docref(NULL, E_NOTICE, "Unknown Tidy Configuration Option '%s'", optname);
292+
php_error_docref(NULL, E_WARNING, "Unknown Tidy configuration option \"%s\"", optname);
293293
return FAILURE;
294294
}
295295

296296
if (tidyOptIsReadOnly(opt)) {
297-
php_error_docref(NULL, E_NOTICE, "Attempting to set read-only option '%s'", optname);
297+
php_error_docref(NULL, E_WARNING, "Attempting to set read-only option \"%s\"", optname);
298298
return FAILURE;
299299
}
300300

@@ -356,8 +356,8 @@ static void php_tidy_quick_repair(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_fil
356356
}
357357

358358
if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(data))) {
359-
php_error_docref(NULL, E_WARNING, "Input string is too long");
360-
RETURN_FALSE;
359+
zend_argument_value_error(1, "is too long");
360+
RETURN_THROWS();
361361
}
362362

363363
doc = tidyCreate();
@@ -382,7 +382,7 @@ static void php_tidy_quick_repair(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_fil
382382

383383
if(enc_len) {
384384
if (tidySetCharEncoding(doc, enc) < 0) {
385-
php_error_docref(NULL, E_WARNING, "Could not set encoding '%s'", enc);
385+
php_error_docref(NULL, E_WARNING, "Could not set encoding \"%s\"", enc);
386386
RETVAL_FALSE;
387387
}
388388
}
@@ -798,7 +798,7 @@ static int php_tidy_parse_string(PHPTidyObj *obj, char *string, uint32_t len, ch
798798

799799
if(enc) {
800800
if (tidySetCharEncoding(obj->ptdoc->doc, enc) < 0) {
801-
php_error_docref(NULL, E_WARNING, "Could not set encoding '%s'", enc);
801+
php_error_docref(NULL, E_WARNING, "Could not set encoding \"%s\"", enc);
802802
return FAILURE;
803803
}
804804
}
@@ -995,8 +995,8 @@ PHP_FUNCTION(tidy_parse_string)
995995
}
996996

997997
if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(input))) {
998-
php_error_docref(NULL, E_WARNING, "Input string is too long");
999-
RETURN_FALSE;
998+
zend_argument_value_error(1, "is too long");
999+
RETURN_THROWS();
10001000
}
10011001

10021002
tidy_instanciate(tidy_ce_doc, return_value);
@@ -1058,13 +1058,13 @@ PHP_FUNCTION(tidy_parse_file)
10581058
obj = Z_TIDY_P(return_value);
10591059

10601060
if (!(contents = php_tidy_file_to_mem(ZSTR_VAL(inputfile), use_include_path))) {
1061-
php_error_docref(NULL, E_WARNING, "Cannot Load '%s' into memory%s", ZSTR_VAL(inputfile), (use_include_path) ? " (Using include path)" : "");
1061+
php_error_docref(NULL, E_WARNING, "Cannot load \"%s\" into memory%s", ZSTR_VAL(inputfile), (use_include_path) ? " (using include path)" : "");
10621062
RETURN_FALSE;
10631063
}
10641064

10651065
if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(contents))) {
1066-
php_error_docref(NULL, E_WARNING, "Input string is too long");
1067-
RETURN_FALSE;
1066+
zend_value_error("Input string is too long");
1067+
RETURN_THROWS();
10681068
}
10691069

10701070
TIDY_APPLY_CONFIG_ZVAL(obj->ptdoc->doc, options);
@@ -1155,8 +1155,8 @@ PHP_FUNCTION(tidy_get_opt_doc)
11551155
opt = tidyGetOptionByName(obj->ptdoc->doc, optname);
11561156

11571157
if (!opt) {
1158-
php_error_docref(NULL, E_WARNING, "Unknown Tidy Configuration Option '%s'", optname);
1159-
RETURN_FALSE;
1158+
zend_argument_value_error(2, "is an invalid configuration option");
1159+
RETURN_THROWS();
11601160
}
11611161

11621162
if ( (optval = (char *) tidyOptGetDoc(obj->ptdoc->doc, opt)) ) {
@@ -1299,8 +1299,8 @@ PHP_FUNCTION(tidy_getopt)
12991299
opt = tidyGetOptionByName(obj->ptdoc->doc, optname);
13001300

13011301
if (!opt) {
1302-
php_error_docref(NULL, E_WARNING, "Unknown Tidy Configuration Option '%s'", optname);
1303-
RETURN_FALSE;
1302+
zend_argument_value_error(2, "is an invalid configuration option");
1303+
RETURN_THROWS();
13041304
}
13051305

13061306
optval = php_tidy_get_opt_val(obj->ptdoc, opt, &optt);
@@ -1350,13 +1350,13 @@ PHP_METHOD(tidy, __construct)
13501350

13511351
if (inputfile) {
13521352
if (!(contents = php_tidy_file_to_mem(ZSTR_VAL(inputfile), use_include_path))) {
1353-
php_error_docref(NULL, E_WARNING, "Cannot Load '%s' into memory%s", ZSTR_VAL(inputfile), (use_include_path) ? " (Using include path)" : "");
1353+
php_error_docref(NULL, E_WARNING, "Cannot load \"%s\" into memory%s", ZSTR_VAL(inputfile), (use_include_path) ? " (using include path)" : "");
13541354
return;
13551355
}
13561356

13571357
if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(contents))) {
1358-
php_error_docref(NULL, E_WARNING, "Input string is too long");
1359-
RETURN_FALSE;
1358+
zend_value_error("Input string is too long");
1359+
RETURN_THROWS();
13601360
}
13611361

13621362
TIDY_APPLY_CONFIG_ZVAL(obj->ptdoc->doc, options);
@@ -1386,13 +1386,13 @@ PHP_METHOD(tidy, parseFile)
13861386
}
13871387

13881388
if (!(contents = php_tidy_file_to_mem(ZSTR_VAL(inputfile), use_include_path))) {
1389-
php_error_docref(NULL, E_WARNING, "Cannot Load '%s' into memory%s", ZSTR_VAL(inputfile), (use_include_path) ? " (Using include path)" : "");
1389+
php_error_docref(NULL, E_WARNING, "Cannot load \"%s\" into memory%s", ZSTR_VAL(inputfile), (use_include_path) ? " (using include path)" : "");
13901390
RETURN_FALSE;
13911391
}
13921392

13931393
if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(contents))) {
1394-
php_error_docref(NULL, E_WARNING, "Input string is too long");
1395-
RETURN_FALSE;
1394+
zend_value_error("Input string is too long");
1395+
RETURN_THROWS();
13961396
}
13971397

13981398
TIDY_APPLY_CONFIG_ZVAL(obj->ptdoc->doc, options);
@@ -1421,8 +1421,8 @@ PHP_METHOD(tidy, parseString)
14211421
}
14221422

14231423
if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(input))) {
1424-
php_error_docref(NULL, E_WARNING, "Input string is too long");
1425-
RETURN_FALSE;
1424+
zend_argument_value_error(1, "is too long");
1425+
RETURN_THROWS();
14261426
}
14271427

14281428
obj = Z_TIDY_P(object);

0 commit comments

Comments
 (0)