Skip to content

Commit

Permalink
backport updates and fixes to v1.15.x (#2953)
Browse files Browse the repository at this point in the history
**What problem is this PR intended to solve?**

Backporting changes from:

- #2927
- #2924
- #2951
  • Loading branch information
flavorjones committed Aug 11, 2023
2 parents 0d545ac + 8460bfe commit 769faec
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/1-bug-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Here's an example of how you might structure such a script:
require 'nokogiri'
require 'minitest/autorun'
class Test < MiniTest::Spec
class Test < Minitest::Spec
describe "Node#css" do
it "should find a div using chained classes" do
html = <<~HEREDOC
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
command: "bundle exec rake spec"
- url: https://github.com/SAML-Toolkits/ruby-saml
name: ruby-saml
command: "bundle exec rake test"
command: "bundle exec rake test MT_COMPAT=t"
# - url: https://github.com/instructure/nokogiri-xmlsec-instructure
# name: nokogiri-xmlsec-instructure
# precommand: "apt install -y libxmlsec1-dev"
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ Nokogiri follows [Semantic Versioning](https://semver.org/), please see the [REA

---

## next / unreleased

### Dependencies

* [CRuby] Vendored libxml2 is updated to v2.11.5 from v2.11.4. For details please see https://gitlab.gnome.org/GNOME/libxml2/-/releases/v2.11.5


### Fixed

* Fixed a typo in a HTML5 parser error message. [[#2927](https://github.com/sparklemotion/nokogiri/issues/2927)] (Thanks, [@anishathalye](https://github.com/anishathalye)!)
* [CRuby] `ObjectSpace.memsize_of` is now safe to call on `Document`s with complex DTDs. In previous versions, this debugging method could result in a segfault. [[#2923](https://github.com/sparklemotion/nokogiri/issues/2923), [#2924](https://github.com/sparklemotion/nokogiri/issues/2924)]


## 1.15.3 / 2023-07-05

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Note that `rake test` does not compile the native extension, and this is intenti
bundle exec rake compile test
```

To run a focused test, use MiniTest's `TESTOPTS`:
To run a focused test, use Minitest's `TESTOPTS`:

``` sh
bundle exec rake compile test TESTOPTS="-n/test_last_element_child/"
Expand Down
6 changes: 3 additions & 3 deletions dependencies.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
libxml2:
version: "2.11.4"
sha256: "737e1d7f8ab3f139729ca13a2494fd17bf30ddb4b7a427cf336252cab57f57f7"
# sha-256 hash provided in https://download.gnome.org/sources/libxml2/2.11/libxml2-2.11.4.sha256sum
version: "2.11.5"
sha256: "3727b078c360ec69fa869de14bd6f75d7ee8d36987b071e6928d4720a28df3a6"
# sha-256 hash provided in https://download.gnome.org/sources/libxml2/2.11/libxml2-2.11.5.sha256sum

libxslt:
version: "1.1.38"
Expand Down
8 changes: 6 additions & 2 deletions ext/nokogiri/xml_document.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,15 @@ memsize_node(const xmlNodePtr node)
{
/* note we don't count namespace definitions, just going for a good-enough number here */
xmlNodePtr child;
xmlAttrPtr property;
size_t memsize = 0;

memsize += xmlStrlen(node->name);
for (child = (xmlNodePtr)node->properties; child; child = child->next) {
memsize += sizeof(xmlAttr) + memsize_node(child);

if (node->type == XML_ELEMENT_NODE) {
for (property = node->properties; property; property = property->next) {
memsize += sizeof(xmlAttr) + memsize_node((xmlNodePtr)property);
}
}
if (node->type == XML_TEXT_NODE) {
memsize += xmlStrlen(node->content);
Expand Down
2 changes: 1 addition & 1 deletion gumbo-parser/src/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ static void handle_parser_error (
print_tag_stack(error, output);
return;
case GUMBO_TOKEN_END_TAG:
print_message(output, "Eng tag '%s' isn't allowed here.",
print_message(output, "End tag '%s' isn't allowed here.",
gumbo_normalized_tagname(error->input_tag));
print_tag_stack(error, output);
return;
Expand Down
4 changes: 2 additions & 2 deletions suppressions/ruby.supp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
fun:evaluate
}
{
TODO
https://github.com/sparklemotion/nokogiri/actions/runs/5354163940/jobs/9710862134
# 240 (120 direct, 120 indirect) bytes in 1 blocks are definitely lost in loss record 28,980 of 37,883
# *xmlNewNodeEatName (tree.c:2299)
# *xmlNewDocNodeEatName (tree.c:2374)
Expand All @@ -117,7 +117,7 @@
fun:xmlNewNodeEatName
fun:xmlNewDocNodeEatName
fun:xmlSAX2StartElementNs
fun:xmlParseStartTag2
fun:xmlParseStartTag*
fun:xmlParseElementStart
fun:xmlParseContentInternal
fun:xmlParseElement
Expand Down
4 changes: 2 additions & 2 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class TestBenchmark < Minitest::BenchSpec
end

# rubocop:disable Style/ClassVars
class TestCase < MiniTest::Spec
class TestCase < Minitest::Spec
include TestBase

COMPACT_EVERY = 20
Expand Down Expand Up @@ -272,7 +272,7 @@ def assert_not_send(send_ary, m = nil)
def pending(msg)
begin
yield
rescue MiniTest::Assertion
rescue Minitest::Assertion
skip("pending #{msg} [#{caller(2..2).first}]")
end
flunk("pending test unexpectedly passed: #{msg} [#{caller(1..1).first}]")
Expand Down
15 changes: 15 additions & 0 deletions test/test_memory_leak.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,21 @@ def test_object_space_memsize_of
assert(bigger_name_size > base_size, "longer tags should increase memsize")
end

def test_object_space_memsize_with_dtd
# https://github.com/sparklemotion/nokogiri/issues/2923
require "objspace"
skip("memsize_of not defined") unless ObjectSpace.respond_to?(:memsize_of)

doc = Nokogiri::XML(<<~XML)
<?xml version="1.0"?>
<!DOCTYPE staff PUBLIC "staff.dtd" [
<!ATTLIST payment type CDATA "check">
]>
<staff></staff>
XML
ObjectSpace.memsize_of(doc) # assert_does_not_crash
end

module MemInfo
# from https://stackoverflow.com/questions/7220896/get-current-ruby-process-memory-usage
# this is only going to work on linux
Expand Down

0 comments on commit 769faec

Please sign in to comment.