From d60035dfde8382769a6458376be1b78faf396e9e 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 --- ext/tidy/tests/gh12980.phpt | 34 ++++++++++++++++++++++++++++++++++ ext/tidy/tidy.c | 8 ++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 ext/tidy/tests/gh12980.phpt diff --git a/ext/tidy/tests/gh12980.phpt b/ext/tidy/tests/gh12980.phpt new file mode 100644 index 0000000000000..042701388a4e5 --- /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 e7b345dd25e34..a2e4dec90a3e1 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 {