Skip to content

Commit 4433986

Browse files
committed
ext/tidy: Refactor php_tidy_parse_string()
1 parent 0a130ca commit 4433986

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

ext/tidy/tidy.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -775,11 +775,13 @@ static zend_result _php_tidy_apply_config_array(TidyDoc doc, const HashTable *ht
775775
}
776776
}
777777

778-
static zend_result php_tidy_parse_string(PHPTidyObj *obj, const char *string, uint32_t len, const char *enc)
778+
static zend_result php_tidy_parse_string(PHPTidyObj *obj, const zend_string *string, const char *enc)
779779
{
780780
TidyBuffer buf;
781781

782-
if(enc) {
782+
ZEND_ASSERT(!ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(string)));
783+
784+
if (enc) {
783785
if (tidySetCharEncoding(obj->ptdoc->doc, enc) < 0) {
784786
php_error_docref(NULL, E_WARNING, "Could not set encoding \"%s\"", enc);
785787
return FAILURE;
@@ -789,9 +791,9 @@ static zend_result php_tidy_parse_string(PHPTidyObj *obj, const char *string, ui
789791
obj->ptdoc->initialized = true;
790792

791793
tidyBufInit(&buf);
792-
tidyBufAttach(&buf, (byte *) string, len);
794+
tidyBufAttach(&buf, (byte *) ZSTR_VAL(string), (unsigned int) ZSTR_LEN(string));
793795
if (tidyParseBuffer(obj->ptdoc->doc, &buf) < 0) {
794-
php_error_docref(NULL, E_WARNING, "%s", obj->ptdoc->errbuf->bp);
796+
php_error_docref(NULL, E_WARNING, "%s", (const char*) obj->ptdoc->errbuf->bp);
795797
return FAILURE;
796798
}
797799
tidy_doc_update_properties(obj);
@@ -995,7 +997,7 @@ PHP_FUNCTION(tidy_parse_string)
995997
obj = Z_TIDY_P(return_value);
996998

997999
if (php_tidy_apply_config(obj->ptdoc->doc, options_str, options_ht, 2) != SUCCESS
998-
|| php_tidy_parse_string(obj, ZSTR_VAL(input), (uint32_t)ZSTR_LEN(input), enc) != SUCCESS) {
1000+
|| php_tidy_parse_string(obj, input, enc) != SUCCESS) {
9991001
zval_ptr_dtor(return_value);
10001002
RETURN_FALSE;
10011003
}
@@ -1063,7 +1065,7 @@ PHP_FUNCTION(tidy_parse_file)
10631065
obj = Z_TIDY_P(return_value);
10641066

10651067
if (php_tidy_apply_config(obj->ptdoc->doc, options_str, options_ht, 2) != SUCCESS
1066-
|| php_tidy_parse_string(obj, ZSTR_VAL(contents), (uint32_t)ZSTR_LEN(contents), enc) != SUCCESS) {
1068+
|| php_tidy_parse_string(obj, contents, enc) != SUCCESS) {
10671069
zval_ptr_dtor(return_value);
10681070
RETVAL_FALSE;
10691071
}
@@ -1348,7 +1350,7 @@ PHP_METHOD(tidy, __construct)
13481350
}
13491351
zend_restore_error_handling(&error_handling);
13501352

1351-
php_tidy_parse_string(obj, ZSTR_VAL(contents), (uint32_t)ZSTR_LEN(contents), enc);
1353+
php_tidy_parse_string(obj, contents, enc);
13521354

13531355
zend_string_release_ex(contents, 0);
13541356
}
@@ -1385,7 +1387,7 @@ PHP_METHOD(tidy, parseFile)
13851387
}
13861388

13871389
RETVAL_BOOL(php_tidy_apply_config(obj->ptdoc->doc, options_str, options_ht, 2) == SUCCESS
1388-
&& php_tidy_parse_string(obj, ZSTR_VAL(contents), (uint32_t)ZSTR_LEN(contents), enc) == SUCCESS);
1390+
&& php_tidy_parse_string(obj, contents, enc) == SUCCESS);
13891391

13901392
zend_string_release_ex(contents, 0);
13911393
}
@@ -1413,7 +1415,7 @@ PHP_METHOD(tidy, parseString)
14131415
obj = Z_TIDY_P(ZEND_THIS);
14141416

14151417
RETURN_BOOL(php_tidy_apply_config(obj->ptdoc->doc, options_str, options_ht, 2) == SUCCESS
1416-
&& php_tidy_parse_string(obj, ZSTR_VAL(input), (uint32_t)ZSTR_LEN(input), enc) == SUCCESS);
1418+
&& php_tidy_parse_string(obj, input, enc) == SUCCESS);
14171419
}
14181420

14191421

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy