Permalink
Browse files

Merge branch 'bug-643-valgrindy-errors'

  • Loading branch information...
2 parents cba9567 + cf7fd3a commit 7be99c42e1f32b7cdc7b2079f38841489d1006a9 @flavorjones flavorjones committed Apr 27, 2012
Showing with 41 additions and 22 deletions.
  1. +3 −3 ROADMAP.md
  2. +11 −11 ext/nokogiri/xml_node.c
  3. +27 −8 test/xml/test_document_fragment.rb
View
@@ -62,9 +62,9 @@
## Encoding
-We have a lot of issues open around encoding. Is this really an issue?
-Somebody who knows something about encoding, and cares, should point
-this one.
+We have a lot of issues open around encoding. How bad are things?
+Would it help if we deprecated support for Ruby 1.8.7? Somebody who
+knows encoding well should head this up.
* Extract EncodingReader as a real object that can be injected
https://groups.google.com/forum/#!msg/nokogiri-talk/arJeAtMqvkg/tGihB-iBRSAJ
@@ -1219,7 +1219,7 @@ static VALUE process_xincludes(VALUE self, VALUE options)
/* TODO: DOCUMENT ME */
static VALUE in_context(VALUE self, VALUE _str, VALUE _options)
{
- xmlNodePtr node, list, child_iter, tmp, node_children, doc_children;
+ xmlNodePtr node, list = 0, child_iter, node_children, doc_children;
xmlNodeSetPtr set;
xmlParserErrors error;
VALUE doc, err;
@@ -1257,18 +1257,18 @@ static VALUE in_context(VALUE self, VALUE _str, VALUE _options)
* is because if there were errors, it's possible for the child pointers
* to be manipulated. */
if (error != XML_ERR_OK) {
- node->doc->children = doc_children;
- node->children = node_children;
+ node->doc->children = doc_children;
+ node->children = node_children;
}
/* make sure parent/child pointers are coherent so an unlink will work
* properly (#331)
*/
child_iter = node->doc->children ;
while (child_iter) {
- if (child_iter->parent != (xmlNodePtr)node->doc)
- child_iter->parent = (xmlNodePtr)node->doc;
- child_iter = child_iter->next;
+ if (child_iter->parent != (xmlNodePtr)node->doc)
+ child_iter->parent = (xmlNodePtr)node->doc;
+ child_iter = child_iter->next;
}
#ifndef HTML_PARSE_NOIMPLIED
@@ -1285,12 +1285,12 @@ static VALUE in_context(VALUE self, VALUE _str, VALUE _options)
* https://bugzilla.gnome.org/show_bug.cgi?id=668155
*/
if (error != XML_ERR_OK && doc_is_empty && node->doc->children != NULL) {
- tmp = node;
- while (tmp->parent)
- tmp = tmp->parent;
+ child_iter = node;
+ while (child_iter->parent)
+ child_iter = child_iter->parent;
- if (tmp->type == XML_DOCUMENT_FRAG_NODE)
- node->doc->children = NULL;
+ if (child_iter->type == XML_DOCUMENT_FRAG_NODE)
+ node->doc->children = NULL;
}
/* FIXME: This probably needs to handle more constants... */
@@ -176,15 +176,34 @@ def awesome!
assert fragment.children.respond_to?(:awesome!), fragment.children.class
end
- def test_for_libxml_in_context_fragment_parsing_bug_workaround
- 10.times do
- begin
- fragment = Nokogiri::XML.fragment("<div></div>")
- parent = fragment.children.first
- child = parent.parse("<h1></h1>").first
- parent.add_child child
+ if Nokogiri.uses_libxml?
+ def test_for_libxml_in_context_fragment_parsing_bug_workaround
+ 10.times do
+ begin
+ fragment = Nokogiri::XML.fragment("<div></div>")
+ parent = fragment.children.first
+ child = parent.parse("<h1></h1>").first
+ parent.add_child child
+ end
+ GC.start
end
- GC.start
+ end
+
+ def test_for_libxml_in_context_memory_badness_when_encountering_encoding_errors
+ # see issue #643 for background
+ # this test exists solely to raise an error during valgrind test runs.
+ html = <<-EOHTML
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=shizzle" />
+ </head>
+ <body>
+ <div>Foo</div>
+ </body>
+</html>
+EOHTML
+ doc = Nokogiri::HTML html
+ doc.at_css("div").replace("Bar")
end
end
end

0 comments on commit 7be99c4

Please sign in to comment.