fix: XML::Reader XML::Attr garbage collection#2599
Merged
flavorjones merged 4 commits intomainfrom Jul 22, 2022
Merged
Conversation
945f617 to
42dd5bb
Compare
which is now being used to implement Reader#attributes fix: Reader#namespaces on JRuby now returns an empty hash when no attributes are present (previously returned nil)
which will use rb_category_warning if it's available, and rb_warning if it's not
This method will be removed in a future version
42dd5bb to
113440c
Compare
flavorjones
added a commit
that referenced
this pull request
Nov 28, 2023
**What problem is this PR intended to solve?** Before a minor release, I generally review deprecations and look for things we can remove. * Removed `Nokogiri::HTML5.get` which was deprecated in v1.12.0. [#2278] (@flavorjones) * Removed the CSS-to-XPath utility modules `XPathVisitorAlwaysUseBuiltins` and `XPathVisitorOptimallyUseBuiltins`, which were deprecated in v1.13.0 in favor of `XPathVisitor` constructor args. [#2403] (@flavorjones) * Removed `XML::Reader#attribute_nodes` which was deprecated in v1.13.8 in favor of `#attribute_hash`. [#2598, #2599] (@flavorjones) Also we're now specifying version numbers in remaining deprecation warnings. **Have you included adequate test coverage?** Tests have been removed, otherwise no new coverage needed. **Does this change affect the behavior of either the C or the Java implementations?** As documented above.
Contributor
:sigh: here I am. https://github.com/instructure/ratom/blob/v0.10.11/lib/atom/xml/parser.rb#L103. I'm not the original author of this code, so I'm not intimately familiar with it. But it sure seems like proper namespace handling is imperative for this code. It needs the attribute name in all forms: with the namespace prefix, and with the namespace href. It doesn't hang on to the attribute node though, so copying out just those values and not having a full xmlAttrPtr is just fine. |
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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_hashthat will return aHash<String ⇒ String>(instead of anArray<XML::Attr>)Reader#attribute_nodeswith a plan to remove it entirely in a future releaseReader#attributesto use#attribute_hash(instead of#attribute_nodes)After this change, only applications calling
Reader#attribute_nodesdirectly will be running the unsafe code. These users will see a deprecation warning and may use#attribute_hashas a replacement.I think it's very possible that
Reader#attribute_hashwon't meet the needs of people who are working with namespaced attributes and are using#attribute_nodesfor 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#attributesis 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#namespacesnow returns an empty hash when there are no namespaces (it previously returnednil).