]> granicus.if.org Git - php/commitdiff
Promote warnings to exceptions in ext/tidy
authorMáté Kocsis <kocsismate@woohoolabs.com>
Fri, 28 Aug 2020 08:27:40 +0000 (10:27 +0200)
committerMáté Kocsis <kocsismate@woohoolabs.com>
Tue, 1 Sep 2020 12:18:02 +0000 (14:18 +0200)
Closes GH-6051

ext/tidy/tests/007.phpt
ext/tidy/tests/019.phpt
ext/tidy/tests/021.phpt
ext/tidy/tests/bug54682.phpt
ext/tidy/tests/tidy_error1.phpt
ext/tidy/tidy.c

index 127dcdf4724d54c9246b45e19f756bf1cd791670..052395711032e5a56f1501d6753a5a3bb2848743 100644 (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 ���');
+} 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 ���" given
index 69d7fd943f213dc867bdc1aaef0adcecb083ec42..2df1c967096bed470b9bf14107f044a29da50655 100644 (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
index bdf954617babd0de63a77b6843b21968017bf0fe..87a4582343bd6cca3436113cebac1e726277ea79 100644 (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)
index 2bebe11bdbd715505b5171f9f4dd7aef2af9239b..174bbb37c429a68c65813af52e9c371abae9b4aa 100644 (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
index a92446925f5e9a7ae261b7378fe06c637c5ce086..a25501352d5251b8e468522e546baf3e6f525fa1 100644 (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)
index 97cb697e99bc8e9b35a6e6c17964e4e1311b2d72..92c88ceaf154434eed62570dfa81d7d3b4c1b7de 100644 (file)
             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);