Skip to content

Add missing error check on tidyLoadConfig #10636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ext/tidy/tests/019.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ 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 the Tidy 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 load configuration file "" in %s on line %d
Warning: tidy_repair_string(): Could not load the Tidy 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 the Tidy configuration file "1" in %s on line %d

Warning: tidy_repair_string(): Could not set encoding "1" in %s on line %d
Path cannot be empty
Expand Down
12 changes: 12 additions & 0 deletions ext/tidy/tests/gh10636.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
GH-10636 (Tidy does not output notice when it encountered parse errors in the default configuration file)
--EXTENSIONS--
tidy
--INI--
tidy.default_config={PWD}/gh10636_config
--FILE--
<?php
$a = new tidy(__DIR__."/007.html");
?>
--EXPECTF--
Notice: main(): There were errors while parsing the Tidy configuration file "%sgh10636_config" in %s on line %d
1 change: 1 addition & 0 deletions ext/tidy/tests/gh10636_config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
indent:@
23 changes: 12 additions & 11 deletions ext/tidy/tidy.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,7 @@
_php_tidy_apply_config_array(_doc, _val_ht); \
} else if (_val_str) { \
TIDY_OPEN_BASE_DIR_CHECK(ZSTR_VAL(_val_str)); \
switch (tidyLoadConfig(_doc, ZSTR_VAL(_val_str))) { \
case -1: \
php_error_docref(NULL, E_WARNING, "Could not load configuration file \"%s\"", ZSTR_VAL(_val_str)); \
break; \
case 1: \
php_error_docref(NULL, E_NOTICE, "There were errors while parsing the configuration file \"%s\"", ZSTR_VAL(_val_str)); \
break; \
} \
php_tidy_load_config(_doc, ZSTR_VAL(_val_str)); \
}


Expand Down Expand Up @@ -143,9 +136,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_tidy_load_config(_doc, TG(default_config)); \
}
/* }}} */

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

static void php_tidy_load_config(TidyDoc doc, const char *path)
{
int ret = tidyLoadConfig(doc, path);
if (ret < 0) {
php_error_docref(NULL, E_WARNING, "Could not load the Tidy configuration file \"%s\"", path);
} else if (ret > 0) {
php_error_docref(NULL, E_NOTICE, "There were errors while parsing the Tidy configuration file \"%s\"", path);
}
}

static int _php_tidy_set_tidy_opt(TidyDoc doc, char *optname, zval *value)
{
TidyOption opt = tidyGetOptionByName(doc, optname);
Expand Down