Fix duplicate responses in XPath following, following-sibling, preceding, preceding-sibling - #255
Merged
kou merged 1 commit intoMay 6, 2025
Conversation
naitoh
marked this pull request as ready for review
May 4, 2025 14:10
Member
|
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> |
naitoh
force-pushed
the
fix_xpath_preceding_following_multiple_case
branch
2 times, most recently
from
May 5, 2025 12:34
2fdf0db to
15b3a80
Compare
Contributor
Author
Thanks! I have corrected the issue you mentioned by removing the duplicate. |
kou
reviewed
May 5, 2025
naitoh
force-pushed
the
fix_xpath_preceding_following_multiple_case
branch
from
May 6, 2025 00:33
15b3a80 to
6e6dfda
Compare
naitoh
force-pushed
the
fix_xpath_preceding_following_multiple_case
branch
from
May 6, 2025 00:49
6e6dfda to
effd307
Compare
Contributor
Author
|
I have corrected the points you pointed out. |
kou
reviewed
May 6, 2025
naitoh
force-pushed
the
fix_xpath_preceding_following_multiple_case
branch
from
May 6, 2025 07:57
effd307 to
0471daf
Compare
Contributor
Author
|
I have corrected the points you pointed out. |
kou
reviewed
May 6, 2025
| <b/><c/><d/><d/><e/><f/> | ||
| </a> | ||
| XML | ||
| d = REXML::Document.new( source ) |
Member
There was a problem hiding this comment.
- Let's use
XXX(YYY)style notXXX( YYY )style for newly added codes - Let's use
docordocumentinstead ofdbecause we have<d/>in this context
Suggested change
| d = REXML::Document.new( source ) | |
| doc = REXML::Document.new(source) |
| </a> | ||
| XML | ||
| d = REXML::Document.new( source ) | ||
| matches = REXML::XPath.match(d, "a/d/preceding::*") |
Member
There was a problem hiding this comment.
Suggested change
| matches = REXML::XPath.match(d, "a/d/preceding::*") | |
| matches = REXML::XPath.match(doc, "a/d/preceding::*") |
…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> ```
naitoh
force-pushed
the
fix_xpath_preceding_following_multiple_case
branch
from
May 6, 2025 12:14
0471daf to
054d207
Compare
Contributor
Author
|
I have corrected the points you pointed out. |
Member
|
Thanks. |
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.
Why?
See: #251 (comment)
Expected values