Skip to content

Fix #79271: DOMDocumentType::$childNodes is NULL #5180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Feb 14, 2020

Dom level 2 core, DOM level 3 core and the DOM living standard agree
that childNodes always return a NodeList, and never null.

Dom level 2 core, DOM level 3 core and the DOM living standard agree
that `childNodes` always return a `NodeList`, and never `null`.
intern = Z_DOMOBJ_P(retval);
dom_namednode_iter(obj, XML_ELEMENT_NODE, intern, NULL, NULL, NULL);
}
php_dom_create_interator(retval, DOM_NODELIST);
Copy link
Member Author

Choose a reason for hiding this comment

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

BTW, what's an "interator"?

@cmb69
Copy link
Member Author

cmb69 commented Feb 14, 2020

cc @beberlei

@beberlei
Copy link
Contributor

This is technically a BC break, but the likelihood of people working with DOMDocumentType directly tends towards 0, so I am fine with it. Wondering if this affects other node classes.

@cmb69
Copy link
Member Author

cmb69 commented Feb 14, 2020

Yes, that is a BC break, so maybe should target an higher branch? Anyway, these node types are affected as well.

@beberlei
Copy link
Contributor

@theseer @ThomasWeinert can I loop you in for a comment?

@ThomasWeinert
Copy link
Contributor

I think the change has little chance to break something. It would make a condition unnecessary (is the property a node list / not null) but in any case the user has to consider an empty node list.

@theseer
Copy link
Contributor

theseer commented Feb 15, 2020

I basically agree with @ThomasWeinert.

A Nodelist could always be empty and any implementation that doesn't check for that might (maybe should?) be considered buggy. It still is a BC break though, as one might have concluded from the property not being null that - logically - the list cannot be empty.

Question is what the real world impact of this change or break would be though, as I don't believe there to be many active uses of DOMDocumentType do begin with and it's property childNodes in particular.

But how many users does it have to affect before it's a BC break to avoid? ;-)
I'd still say it's a valid change to fix a bug for something that doesn't work according to specs and code, in case it didn't check for empty lists, should just get adjusted.

@cmb69
Copy link
Member Author

cmb69 commented Feb 17, 2020

Thanks everyone for the feedback!

Applied the patch as 0966941.

@cmb69 cmb69 closed this Feb 17, 2020
@cmb69 cmb69 deleted the cmb/79271 branch February 17, 2020 08:13
@beberlei
Copy link
Contributor

@cmb69 Derick reported a change in xdebug tests failing on 7.3, is this change related? I don't see how on the first glance. https://xdebug.org/ci?r=2020-24-24-03-20-01@7.3dev-zts

@cmb69
Copy link
Member Author

cmb69 commented Feb 24, 2020

@beberlei, @derickr, this test failure is to be expected after this commit; the Text node now has an empty NodeList as childNodes instead of NULL before. Revert this commit from 7.3 (and maybe 7.4), or stick with the BC break?

@cmb69
Copy link
Member Author

cmb69 commented Feb 24, 2020

Alternatively, maybe add a node to UPGRADING?

Test fix:

 tests/base/bug00913.phpt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/base/bug00913.phpt b/tests/base/bug00913.phpt
index cd451134..3be71334 100644
--- a/tests/base/bug00913.phpt
+++ b/tests/base/bug00913.phpt
@@ -181,7 +181,7 @@ object(DOMText)#%d (%d) {
   ["parentNode"]=>
   string(22) "(object value omitted)"
   ["childNodes"]=>
-  NULL
+  string(22) "(object value omitted)"
   ["firstChild"]=>
   NULL
   ["lastChild"]=>

@derickr
Copy link
Member

derickr commented Feb 24, 2020

This isn't the only change in the test I think, there are also these:

056+   ["nextSibling"]=>
057+   NULL

@cmb69
Copy link
Member Author

cmb69 commented Feb 24, 2020

@derickr, nope, these are otherwise catched by the %as; it's just a glitch of the test runner's diff that these are reported.

@theseer
Copy link
Contributor

theseer commented Feb 25, 2020

In case it matters: I'd keep the - as stated before - minor BC break but adding a note might be a good idea never the less.

@cmb69
Copy link
Member Author

cmb69 commented Feb 27, 2020

UPGRADING note added with commit 49762c8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants