Document how Element#attribute matches a namespace - #360
Merged
Conversation
REXML::Element#attribute matches its +namespace+ argument loosely: an
unprefixed attribute is taken to be in the default namespace, and a
namespace that no prefix is bound to falls back to the unprefixed
attribute.
<root xmlns='ns0' a='a'/>
attribute("a", "ns0") -> a='a'
attribute("a", "nosuch") -> a='a'
The XML Namespaces specification says an unprefixed attribute has no
namespace and does not take the default one, so neither of those should
match. The
behavior is kept for compatibility -- it is what tickets 102 and 121
asked for, and the tests for both are still in place -- but nothing said
so, which has left people reading the method unsure whether what they
saw was the contract or a bug.
Say it in the documentation of both methods, and point each at the
other: REXML::Attributes#get_attribute_ns matches as the XML Namespaces
specification says and is what to reach for when the namespace has to be
matched strictly. It has behaved that way at least as far back as rubyGH-151, but
that discussion never mentioned it.
GitHub: rubyGH-151
Contributor
Author
|
Based on the discussion below, we will update the documentation for |
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.
GitHub: Fix GH-151
REXML::Element#attributematches its +namespace+ argument loosely: an unprefixed attribute is taken to be in the default namespace, and a namespace that no prefix is bound to falls back to the unprefixed attribute.The XML Namespaces specification says an unprefixed attribute has no namespace and does not take the default one, so neither of those should match. The
behavior is kept for compatibility -- it is what tickets 102 and 121 asked for, and the tests for both are still in place -- but nothing said so, which has left people reading the method unsure whether what they saw was the contract or a bug.
Say it in the documentation of both methods, and point each at the other: REXML::Attributes#get_attribute_ns matches as the XML Namespaces specification says and is what to reach for when the namespace has to be matched strictly. It has behaved that way at least as far back as GH-151, but that discussion never mentioned it.
Reported by Hiroya Fujinami. Thanks!!!