fix: XML::Reader XML::Attr garbage collection #2599
Merged
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.
Suggestion cannot be applied right now. Please check back later.
What problem is this PR intended to solve?
This is a proposed fix for #2598, see that issue for an extended explanation of the problem.
This PR implements "option 2" from that issue's proposed solutions:
Reader#attribute_hash
that will return aHash<String ⇒ String>
(instead of anArray<XML::Attr>
)Reader#attribute_nodes
with a plan to remove it entirely in a future releaseReader#attributes
to use#attribute_hash
(instead of#attribute_nodes
)After this change, only applications calling
Reader#attribute_nodes
directly will be running the unsafe code. These users will see a deprecation warning and may use#attribute_hash
as a replacement.I think it's very possible that
Reader#attribute_hash
won't meet the needs of people who are working with namespaced attributes and are using#attribute_nodes
for this purpose. However, I'm intentionally deferring any attempt to solve that DX problem until someone who needs this functionality asks for it.Have you included adequate test coverage?
I tried and failed to add test coverage to the suite that would reproduce the underlying GC bug.
However, existing test coverage of
Reader#attributes
is sufficient for now.Does this change affect the behavior of either the C or the Java implementations?
This PR modifies both the C and Java implementations to behave the same.
Notably, the Java implementation contains a small bugfix which is that
Reader#namespaces
now returns an empty hash when there are no namespaces (it previously returnednil
).