Skip to content
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

Reset xmlXPathContext state variables before each evaluation #3386

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Nokogiri follows [Semantic Versioning](https://semver.org/), please see the [REA

---

## 1.18.0.rc1 / 2024-12-16
## v1.18.0.rc1 / 2024-12-16

### Notable Changes

Expand Down
11 changes: 11 additions & 0 deletions ext/nokogiri/xml_xpath_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,17 @@ noko_xml_xpath_context_set_node(VALUE rb_context, VALUE rb_node)
c_context->doc = c_node->doc;
c_context->node = c_node;

/* Note from @nwellnof in https://github.com/sparklemotion/nokogiri/pull/3378#issuecomment-2557001734:
*
* > Note that if you use a single XPath context and support custom XPath extension functions, a
* > custom function could evaluate XPath expressions recursively which will lead to corruption of
* > context variables. This is mostly due to some design mistakes in libxml2.
*
* So let's set these context variables back to their default.
*/
c_context->contextSize = -1;
c_context->proximityPosition = -1;

return rb_node;
}

Expand Down
Loading