-
Notifications
You must be signed in to change notification settings - Fork 76
Fix duplicate responses in XPath following, following-sibling, preceding, preceding-sibling #255
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
Fix duplicate responses in XPath following, following-sibling, preceding, preceding-sibling #255
Conversation
It has a breaking change. d = REXML::Document.new('<div>
<div>
<a/><w/>
</div>
<a/><x/>
<a/><y/>
<a/><z/>
</div>')
# Finds a node flowing <a/>
REXML::XPath.match(d, '//a/following-sibling::*[1]')
# Before: [<w/>, <x/>, <y/>, <z/>]
# After: [<w/>, <x/>] For reference, the behavior in master branch is same as JavaScript xpath. document.body.innerHTML = `
<div>
<div><a></a><w></w></div>
<a></a><x></x>
<a></a><y></y>
<a></a><z></z>
</div>`
result = document.evaluate('//a/following-sibling::*[1]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
for(i=0;i<result.snapshotLength;i++) console.log(i, result.snapshotItem(i))
// 0 <w></w>
// 1 <x></x>
// 2 <y></y>
// 3 <z></z> |
2fdf0db
to
15b3a80
Compare
Thanks! I have corrected the issue you mentioned by removing the duplicate. |
15b3a80
to
6e6dfda
Compare
6e6dfda
to
effd307
Compare
I have corrected the points you pointed out. |
effd307
to
0471daf
Compare
I have corrected the points you pointed out. |
test/xpath/test_base.rb
Outdated
<b/><c/><d/><d/><e/><f/> | ||
</a> | ||
XML | ||
d = REXML::Document.new( source ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Let's use
XXX(YYY)
style notXXX( YYY )
style for newly added codes - Let's use
doc
ordocument
instead ofd
because we have<d/>
in this context
d = REXML::Document.new( source ) | |
doc = REXML::Document.new(source) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.
I see.
test/xpath/test_base.rb
Outdated
</a> | ||
XML | ||
d = REXML::Document.new( source ) | ||
matches = REXML::XPath.match(d, "a/d/preceding::*") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
matches = REXML::XPath.match(d, "a/d/preceding::*") | |
matches = REXML::XPath.match(doc, "a/d/preceding::*") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.
I see.
…ing, preceding-sibling ## Why? See: ruby#251 (comment) - XPath : a/d/preceding::* => ["d", "c", "b"] ```xml <a> <b/> <!-- a/d/preceding::b --> <c/> <!-- a/d/preceding::c --> <d/> <!-- a/d/preceding::d --> <d/> <!-- self --> <e/> <f/> </a> ``` - XPath : a/d/following::* => ["d", "e", "f"] ```xml <a> <b/> <c/> <d/> <!-- self --> <d/> <!-- a/d/following::d --> <e/> <!-- a/d/following::e --> <f/> <!-- a/d/following::f --> </a> ``` - XPath : a/b/x/following-sibling:* => ["c", "d", "e"] ```xml <a> <b> <x/> <!-- self --> <c/> <!-- a/b/x/following-sibling::c --> <d/> <!-- a/b/x/following-sibling::d --> </b> <b> <x/> <!-- self --> <e/> <!-- a/b/x/following-sibling::e --> </b> </a> ``` - XPath : a/b/x/following-sibling:* => ["c", "d", "x", "e"] ```xml <a> <b> <x/> <!-- self --> <c/> <!-- a/b/x/following-sibling::c --> <d/> <!-- a/b/x/following-sibling::d --> <x/> <!-- a/b/x/following-sibling::x --> <e/> <!-- a/b/x/following-sibling::e --> </b> </a> ``` - XPath : a/b/x/preceding-sibling::* => ["e", "d", "c"] ```xml <a> <b> <c/> <!-- a/b/x/preceding-sibling::c --> <d/> <!-- a/b/x/preceding-sibling::d --> <x/> <!-- self --> </b> <b> <e/> <!-- a/b/x/preceding-sibling::e --> <x/> <!-- self --> </b> </a> ``` - XPath : a/b/x/preceding-sibling::* => ["e", "x", "d", "c"] ```xml <a> <b> <c/> <!-- a/b/x/preceding-sibling::c --> <d/> <!-- a/b/x/preceding-sibling::d --> <x/> <!-- a/b/x/preceding-sibling::x --> <e/> <!-- a/b/x/preceding-sibling::e --> <x/> <!-- self --> </b> </a> ``` - XPath : //a/following-sibling:*[1] => ["w", "x", "y", "z"] ```xml <div> <div> <a/> <-- self --> <w/> <-- //a/following-sibling:*[1] --> </div> <a/> <-- self --> <x/> <-- //a/following-sibling:*[1] --> <a/> <-- self --> <y/> <-- //a/following-sibling:*[1] --> <a/> <-- self --> <z/> <-- //a/following-sibling:*[1] --> </div> ```
0471daf
to
054d207
Compare
I have corrected the points you pointed out. |
Thanks. |
Why?
See: #251 (comment)
Expected values