diff --git a/ext/tidy/tests/uninitialized.phpt b/ext/tidy/tests/uninitialized.phpt new file mode 100644 index 00000000000..3533f0d3453 --- /dev/null +++ b/ext/tidy/tests/uninitialized.phpt @@ -0,0 +1,29 @@ +--TEST-- +Operations on uninitialized tidy object +--SKIPIF-- + +--FILE-- +getHtmlVer()); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} +try { + var_dump($tidy->isXhtml()); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} +try { + var_dump($tidy->isXml()); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +tidy object is not initialized +tidy object is not initialized +tidy object is not initialized diff --git a/ext/tidy/tidy.c b/ext/tidy/tidy.c index 0efa594b690..8d87bb980c1 100644 --- a/ext/tidy/tidy.c +++ b/ext/tidy/tidy.c @@ -59,6 +59,13 @@ } \ obj = Z_TIDY_P(object); \ +#define TIDY_FETCH_INITIALIZED_OBJECT \ + TIDY_FETCH_OBJECT; \ + if (!obj->ptdoc->initialized) { \ + zend_throw_error(NULL, "tidy object is not initialized"); \ + return; \ + } + #define TIDY_FETCH_ONLY_OBJECT \ PHPTidyObj *obj; \ TIDY_SET_CONTEXT; \ @@ -1229,7 +1236,7 @@ PHP_FUNCTION(tidy_get_status) /* {{{ Get the Detected HTML version for the specified document. */ PHP_FUNCTION(tidy_get_html_ver) { - TIDY_FETCH_OBJECT; + TIDY_FETCH_INITIALIZED_OBJECT; RETURN_LONG(tidyDetectedHtmlVersion(obj->ptdoc->doc)); } @@ -1238,7 +1245,7 @@ PHP_FUNCTION(tidy_get_html_ver) /* {{{ Indicates if the document is a XHTML document. */ PHP_FUNCTION(tidy_is_xhtml) { - TIDY_FETCH_OBJECT; + TIDY_FETCH_INITIALIZED_OBJECT; RETURN_BOOL(tidyDetectedXhtml(obj->ptdoc->doc)); } @@ -1247,7 +1254,7 @@ PHP_FUNCTION(tidy_is_xhtml) /* {{{ Indicates if the document is a generic (non HTML/XHTML) XML document. */ PHP_FUNCTION(tidy_is_xml) { - TIDY_FETCH_OBJECT; + TIDY_FETCH_INITIALIZED_OBJECT; RETURN_BOOL(tidyDetectedGenericXml(obj->ptdoc->doc)); }