Skip to content

Commit e093ac4

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Fix incorrect error check in browsecap for pcre2_match() Add missing error check on tidyLoadConfig
2 parents 263b22f + 0f394ec commit e093ac4

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

ext/standard/browscap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ static int browser_reg_compare(browscap_entry *entry, zend_string *agent_name, b
612612
}
613613
rc = pcre2_match(re, (PCRE2_SPTR)ZSTR_VAL(agent_name), ZSTR_LEN(agent_name), 0, 0, match_data, php_pcre_mctx());
614614
php_pcre_free_match_data(match_data);
615-
if (PCRE2_ERROR_NOMATCH != rc) {
615+
if (rc >= 0) {
616616
/* If we've found a possible browser, we need to do a comparison of the
617617
number of characters changed in the user agent being checked versus
618618
the previous match found and the current match. */

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
#define TIDY_OPEN_BASE_DIR_CHECK(filename) \
@@ -96,9 +89,7 @@ if (php_check_open_basedir(filename)) { \
9689

9790
#define TIDY_SET_DEFAULT_CONFIG(_doc) \
9891
if (TG(default_config) && TG(default_config)[0]) { \
99-
if (tidyLoadConfig(_doc, TG(default_config)) < 0) { \
100-
php_error_docref(NULL, E_WARNING, "Unable to load Tidy configuration file at \"%s\"", TG(default_config)); \
101-
} \
92+
php_tidy_load_config(_doc, TG(default_config)); \
10293
}
10394
/* }}} */
10495

@@ -220,6 +211,16 @@ static void TIDY_CALL php_tidy_panic(ctmbstr msg)
220211
php_error_docref(NULL, E_ERROR, "Could not allocate memory for tidy! (Reason: %s)", (char *)msg);
221212
}
222213

214+
static void php_tidy_load_config(TidyDoc doc, const char *path)
215+
{
216+
int ret = tidyLoadConfig(doc, path);
217+
if (ret < 0) {
218+
php_error_docref(NULL, E_WARNING, "Could not load the Tidy configuration file \"%s\"", path);
219+
} else if (ret > 0) {
220+
php_error_docref(NULL, E_NOTICE, "There were errors while parsing the Tidy configuration file \"%s\"", path);
221+
}
222+
}
223+
223224
static int _php_tidy_set_tidy_opt(TidyDoc doc, char *optname, zval *value)
224225
{
225226
TidyOption opt = tidyGetOptionByName(doc, optname);

0 commit comments

Comments
 (0)