-
Notifications
You must be signed in to change notification settings - Fork 3
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
Check if search index out of bounds #21
Conversation
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.
Hi, thanks for your PR.
FYI the indexing in general is currently broken and requires much larger changes; it indexes based on the entire set of nodes, rather than for each parent node.
For example, applying //node/div[1]
to the html below should return <div>hello</div>
and <div>world</div>
but actually only returns <div>hello</div>
.
<root>
<node>
<div>hello</div>
<div>foo</div>
</node>
<node>
<div>world</div>
<div>bar</div>
</node>
<node>
<p>not a div</p>
</node>
</root>
I'm currently working on a full rewrite of the XPath side of the library since it was originally hacked together without regard for the official XPath specification as a "good enough" library for another project I had.
I'm putting my effort towards the rewrite (which is quite an undertaking) rather than fixing this code master...james/nom
Just to avoid the panic I'll accept these changes if you fix the off-by-one error and ensure if the index is greater than the matched nodes, none are returned rather than all.
@James-LG that's awesome news, thanks for your effort! In the last week I was having a deep dive of the current main branch and noticed some things, which maybe you're already addressing in the new version:
BTW, I'll take a look to the new |
I'd like to get the basic use-cases working first, so the structure is a bit more settled than it currently is, but after that support on things like the |
Clear! Do you have a roadmap in place? Or a discord channel to post updates? |
Since GitHub apparently doesn't have direct messaging I created a brand new discord channel https://discord.gg/jWK42bWK As for roadmap, I don't have anything formal. Vaguely it will be getting basic steps working |
Problem
Let's assume I want to search for a strong[1], with a parent node //div, but some of the divs don't have it. As the search is implemented right now, the code will just panic, since it does not handle out of bound indexing.
Solution
Just add a simple check on the search index. I didn't fix it deeper, at the DocumentNodeSet level, since raw indexing is heavily used in a lot of places and would require more effort.