Skip to content

Commit 266ebbf

Browse files
committed
Add missing error check on tidyLoadConfig
Parse errors were not reported for the default config, they were only reported when explicitly another config was loaded. This means that users may not be aware of errors in their configuration and therefore the behaviour of Tidy might not be what they intended. This patch fixes that issue by using a common function. In fact, the check for -1 might be enough for the current implementation of Tidy, but the Tidy docs say that any value other than 0 indicates an error. So future errors might not be caught when just using an error code of -1. Therefore, this also changes the error code checks of == -1 to < 0 and == 1 to > 0.
1 parent 52c96f2 commit 266ebbf

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

ext/tidy/tests/019.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ 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 the Tidy configuration file "1" in %s on line %d
3232

3333
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 the Tidy 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 the Tidy configuration file "1" in %s on line %d
3838

3939
Warning: tidy_repair_string(): Could not set encoding "1" in %s on line %d
4040
Path cannot be empty

ext/tidy/tests/gh10636.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
GH-10636 (Tidy does not output notice when it encountered parse errors in the default configuration file)
3+
--EXTENSIONS--
4+
tidy
5+
--INI--
6+
tidy.default_config={PWD}/gh10636_config
7+
--FILE--
8+
<?php
9+
$a = new tidy(__DIR__."/007.html");
10+
?>
11+
--EXPECTF--
12+
Notice: main(): There were errors while parsing the Tidy configuration file "%sgh10636_config" in %s on line %d

ext/tidy/tests/gh10636_config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
indent:@

ext/tidy/tidy.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,7 @@
7979
_php_tidy_apply_config_array(_doc, _val_ht); \
8080
} else if (_val_str) { \
8181
TIDY_OPEN_BASE_DIR_CHECK(ZSTR_VAL(_val_str)); \
82-
switch (tidyLoadConfig(_doc, ZSTR_VAL(_val_str))) { \
83-
case -1: \
84-
php_error_docref(NULL, E_WARNING, "Could not load configuration file \"%s\"", ZSTR_VAL(_val_str)); \
85-
break; \
86-
case 1: \
87-
php_error_docref(NULL, E_NOTICE, "There were errors while parsing the configuration file \"%s\"", ZSTR_VAL(_val_str)); \
88-
break; \
89-
} \
82+
php_tidy_load_config(_doc, ZSTR_VAL(_val_str)); \
9083
}
9184

9285

@@ -143,9 +136,7 @@ if (php_check_open_basedir(filename)) { \
143136

144137
#define TIDY_SET_DEFAULT_CONFIG(_doc) \
145138
if (TG(default_config) && TG(default_config)[0]) { \
146-
if (tidyLoadConfig(_doc, TG(default_config)) < 0) { \
147-
php_error_docref(NULL, E_WARNING, "Unable to load Tidy configuration file at \"%s\"", TG(default_config)); \
148-
} \
139+
php_tidy_load_config(_doc, TG(default_config)); \
149140
}
150141
/* }}} */
151142

@@ -269,6 +260,16 @@ static void TIDY_CALL php_tidy_panic(ctmbstr msg)
269260
php_error_docref(NULL, E_ERROR, "Could not allocate memory for tidy! (Reason: %s)", (char *)msg);
270261
}
271262

263+
static void php_tidy_load_config(TidyDoc doc, const char *path)
264+
{
265+
int ret = tidyLoadConfig(doc, path);
266+
if (ret < 0) {
267+
php_error_docref(NULL, E_WARNING, "Could not load the Tidy configuration file \"%s\"", path);
268+
} else if (ret > 0) {
269+
php_error_docref(NULL, E_NOTICE, "There were errors while parsing the Tidy configuration file \"%s\"", path);
270+
}
271+
}
272+
272273
static int _php_tidy_set_tidy_opt(TidyDoc doc, char *optname, zval *value)
273274
{
274275
TidyOption opt = tidyGetOptionByName(doc, optname);

0 commit comments

Comments
 (0)