Skip to content
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: 6 additions & 0 deletions ext/tidy/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ if test "$PHP_TIDY" != "no"; then
[],
[-L$TIDY_LIBDIR])

PHP_CHECK_LIBRARY([$TIDY_LIB_NAME], [tidyParseString],
[AC_DEFINE([HAVE_TIDYPARSESTRING], [1],
[Define to 1 if Tidy library has the 'tidyParseString' function.])],
[],
[-L$TIDY_LIBDIR])

PHP_ADD_LIBRARY_WITH_PATH([$TIDY_LIB_NAME],
[$TIDY_LIBDIR],
[TIDY_SHARED_LIBADD])
Expand Down
8 changes: 6 additions & 2 deletions ext/tidy/tidy.c
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,6 @@ static zend_result _php_tidy_apply_config_array(TidyDoc doc, const HashTable *ht

static zend_result php_tidy_parse_string(PHPTidyObj *obj, const char *string, uint32_t len, const char *enc)
{
TidyBuffer buf;

if(enc) {
if (tidySetCharEncoding(obj->ptdoc->doc, enc) < 0) {
php_error_docref(NULL, E_WARNING, "Could not set encoding \"%s\"", enc);
Expand All @@ -809,9 +807,15 @@ static zend_result php_tidy_parse_string(PHPTidyObj *obj, const char *string, ui

obj->ptdoc->initialized = true;

#ifdef HAVE_TIDYPARSESTRING
if (tidyParseString(obj->ptdoc->doc, string) < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://3v4l.org/KMN1s (edit the repro slightly, as tidy ext is available for live/wasm preview only)

I guess this will stop parsing on the first null byte. Currently explicit length is honored.

#else
TidyBuffer buf;

tidyBufInit(&buf);
tidyBufAttach(&buf, (byte *) string, len);
if (tidyParseBuffer(obj->ptdoc->doc, &buf) < 0) {
#endif
php_error_docref(NULL, E_WARNING, "%s", obj->ptdoc->errbuf->bp);
return FAILURE;
}
Expand Down