Skip to content

Commit 729b8d7

Browse files
committed
ext/tidy: using tidyParseString when available instead for tidy::parseString().
1 parent f6380e4 commit 729b8d7

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

ext/tidy/config.m4

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ if test "$PHP_TIDY" != "no"; then
6363
[],
6464
[-L$TIDY_LIBDIR])
6565

66+
PHP_CHECK_LIBRARY([$TIDY_LIB_NAME], [tidyParseString],
67+
[AC_DEFINE([HAVE_TIDYPARSESTRING], [1],
68+
[Define to 1 if Tidy library has the 'tidyParseString' function.])],
69+
[],
70+
[-L$TIDY_LIBDIR])
71+
6672
PHP_ADD_LIBRARY_WITH_PATH([$TIDY_LIB_NAME],
6773
[$TIDY_LIBDIR],
6874
[TIDY_SHARED_LIBADD])

ext/tidy/tidy.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,8 +798,6 @@ static zend_result _php_tidy_apply_config_array(TidyDoc doc, const HashTable *ht
798798

799799
static zend_result php_tidy_parse_string(PHPTidyObj *obj, const char *string, uint32_t len, const char *enc)
800800
{
801-
TidyBuffer buf;
802-
803801
if(enc) {
804802
if (tidySetCharEncoding(obj->ptdoc->doc, enc) < 0) {
805803
php_error_docref(NULL, E_WARNING, "Could not set encoding \"%s\"", enc);
@@ -809,9 +807,15 @@ static zend_result php_tidy_parse_string(PHPTidyObj *obj, const char *string, ui
809807

810808
obj->ptdoc->initialized = true;
811809

810+
#ifdef HAVE_TIDYPARSESTRING
811+
if (tidyParseString(obj->ptdoc->doc, string) < 0) {
812+
#else
813+
TidyBuffer buf;
814+
812815
tidyBufInit(&buf);
813816
tidyBufAttach(&buf, (byte *) string, len);
814817
if (tidyParseBuffer(obj->ptdoc->doc, &buf) < 0) {
818+
#endif
815819
php_error_docref(NULL, E_WARNING, "%s", obj->ptdoc->errbuf->bp);
816820
return FAILURE;
817821
}

0 commit comments

Comments
 (0)