From b3f483db2e371d558708f750edf1ad56ca1065d7 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Thu, 21 Dec 2023 17:37:05 +0100 Subject: [PATCH] Fix GH-12980: tidynode.props.attribute is missing "Boolean Attributes" and empty attributes Closes GH-12993. --- NEWS | 4 ++++ ext/tidy/tests/gh12980.phpt | 34 ++++++++++++++++++++++++++++++++++ ext/tidy/tidy.c | 8 ++++++-- 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 ext/tidy/tests/gh12980.phpt diff --git a/NEWS b/NEWS index e74c11bafc6..c68a4d19740 100644 --- a/NEWS +++ b/NEWS @@ -46,6 +46,10 @@ PHP NEWS . Fix getting the address of an uninitialized property of a SimpleXMLElement resulting in a crash. (nielsdos) +- Tidy: + . Fixed bug GH-12980 (tidynode.props.attribute is missing + "Boolean Attributes" and empty attributes). (nielsdos) + 21 Dec 2023, PHP 8.2.14 - Core: diff --git a/ext/tidy/tests/gh12980.phpt b/ext/tidy/tests/gh12980.phpt new file mode 100644 index 00000000000..042701388a4 --- /dev/null +++ b/ext/tidy/tests/gh12980.phpt @@ -0,0 +1,34 @@ +--TEST-- +GH-12980 (tidynode.props.attribute is missing "Boolean Attributes" and empty attributes) +--EXTENSIONS-- +tidy +--FILE-- +'; + +$tidy = new tidy(); +$tidy->ParseString($html); +echo tidy_get_output($tidy), "\n"; + +var_dump($tidy->root()->child[1]->attribute); + +?> +--EXPECT-- + + + + + + + + +array(4) { + ["lang"]=> + string(2) "en" + ["boolean"]=> + string(0) "" + ["empty"]=> + string(0) "" + ["selected"]=> + string(8) "selected" +} diff --git a/ext/tidy/tidy.c b/ext/tidy/tidy.c index e7b345dd25e..a2e4dec90a3 100644 --- a/ext/tidy/tidy.c +++ b/ext/tidy/tidy.c @@ -662,8 +662,12 @@ static void tidy_add_node_default_properties(PHPTidyObj *obj) do { name = (char *)tidyAttrName(tempattr); val = (char *)tidyAttrValue(tempattr); - if (name && val) { - add_assoc_string(&attribute, name, val); + if (name) { + if (val) { + add_assoc_string(&attribute, name, val); + } else { + add_assoc_str(&attribute, name, zend_empty_string); + } } } while((tempattr = tidyAttrNext(tempattr))); } else {