/ nokogiri Public
Restore Builder namespace inheritance behavior, and introduce Document#namespace_inheritance #2320
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge.
What problem is this PR intended to solve?
Document#namespace_inheritanceatttribute which defaults to
truebut allows it to be overridden via constructor parameter
I'd like this to be backported to v1.12.
Prior to v1.12.0, the CRuby and JRuby implementations had different behavior with respect to how children inherit namespaces when added to a parent node (via the
Node#add_childfamily of methods). In CRuby, children without a namespace would automatically inherit their new parent's namespace (a bug originally reported in 2011 at #425). In JRuby, this was not the case and the child would either have the document's default namespace or no namespace.
In v1.12.0, a intentional change was introduced to the CRuby implementation to bring it in line with the JRuby implementation. While the maintainers consider this a "bug" "fix", it was nevertheless a breaking change for some libraries and users (see, for example, ebeigarts/signer#30).
In addition, the intentional "fix" in v1.12.0 introduced an unintentional regression in
Nokogiri::XML::Builderin which we actually do want children to inherit their parent's namespace by default (see, for example, #2317).
That said, there's evidence that users may want different namespace inheritance behavior depending on the situation. For example, #1712 requests a way to avoid Builder namespace inheritance.
Have you included adequate test coverage?
Yes. Historically the incompleteness of test coverage around namespaces during reparenting has been an issue, but I believe we now have adequate coverage to prevent regressions.
Does this change affect the behavior of either the C or the Java implementations?
Previously the C and Java implementations had different behavior; v1.12.0 improved that somewhat; this changeset includes changes to bring them completely in line with each other (as far as our current test coverage goes).