Compare commits
No commits in common. "b94ff9f6a10f959e3181cd3c09336cf298aad6c6" and "2bbf19f412eeb4ed87e29000c7bcda7b00119df7" have entirely different histories.
b94ff9f6a1
...
2bbf19f412
65
CVE-2020-26247-pre.patch
Normal file
65
CVE-2020-26247-pre.patch
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
From 74abb4f2e73bb61b17d9f1a0ad717c881943b877 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Aaron Patterson <aaron.patterson@gmail.com>
|
||||||
|
Date: Wed, 26 Feb 2020 13:51:43 -0800
|
||||||
|
Subject: [PATCH] Work around a bug in libxml2
|
||||||
|
|
||||||
|
This commit works around a bug in libxml2 where parsing schemas can
|
||||||
|
result in dangling pointers which can lead to a segv.
|
||||||
|
|
||||||
|
Upstream bug is here: https://gitlab.gnome.org/GNOME/libxml2/issues/148
|
||||||
|
|
||||||
|
Fixes #1985
|
||||||
|
---
|
||||||
|
ext/nokogiri/xml_schema.c | 29 +++++++++++++++++++++++++++++
|
||||||
|
1 file changed, 29 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/ext/nokogiri/xml_schema.c b/ext/nokogiri/xml_schema.c
|
||||||
|
index da2774b..439f721 100644
|
||||||
|
--- a/ext/nokogiri/xml_schema.c
|
||||||
|
+++ b/ext/nokogiri/xml_schema.c
|
||||||
|
@@ -133,6 +133,31 @@ static VALUE read_memory(VALUE klass, VALUE content)
|
||||||
|
return rb_schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
+/* Schema creation will remove and deallocate "blank" nodes.
|
||||||
|
+ * If those blank nodes have been exposed to Ruby, they could get freed
|
||||||
|
+ * out from under the VALUE pointer. This function checks to see if any of
|
||||||
|
+ * those nodes have been exposed to Ruby, and if so we should raise an exception.
|
||||||
|
+ */
|
||||||
|
+static int has_blank_nodes_p(VALUE cache)
|
||||||
|
+{
|
||||||
|
+ long i;
|
||||||
|
+
|
||||||
|
+ if (NIL_P(cache)) {
|
||||||
|
+ return 0;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ for (i = 0; i < RARRAY_LEN(cache); i++) {
|
||||||
|
+ xmlNodePtr node;
|
||||||
|
+ VALUE element = rb_ary_entry(cache, i);
|
||||||
|
+ Data_Get_Struct(element, xmlNode, node);
|
||||||
|
+ if (xmlIsBlankNode(node)) {
|
||||||
|
+ return 1;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return 0;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
/*
|
||||||
|
* call-seq:
|
||||||
|
* from_document(doc)
|
||||||
|
@@ -152,6 +177,10 @@ static VALUE from_document(VALUE klass, VALUE document)
|
||||||
|
/* In case someone passes us a node. ugh. */
|
||||||
|
doc = doc->doc;
|
||||||
|
|
||||||
|
+ if (has_blank_nodes_p(DOC_NODE_CACHE(doc))) {
|
||||||
|
+ rb_raise(rb_eArgError, "Creating a schema from a document that has blank nodes exposed to Ruby is dangerous");
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
ctx = xmlSchemaNewDocParserCtxt(doc);
|
||||||
|
|
||||||
|
errors = rb_ary_new();
|
||||||
|
--
|
||||||
|
2.23.0
|
||||||
|
|
||||||
278
CVE-2020-26247.patch
Normal file
278
CVE-2020-26247.patch
Normal file
@ -0,0 +1,278 @@
|
|||||||
|
From 9c87439d9afa14a365ff13e73adc809cb2c3d97b Mon Sep 17 00:00:00 2001
|
||||||
|
From: Mike Dalessio <mike.dalessio@gmail.com>
|
||||||
|
Date: Mon, 23 Nov 2020 00:47:02 -0500
|
||||||
|
Subject: [PATCH] feat: XML::Schema and RelaxNG creation accept optional
|
||||||
|
ParseOptions
|
||||||
|
|
||||||
|
I'm trying out a new pattern, which is that the parsed object carries
|
||||||
|
around the ParseOptions it was created with, which should make some
|
||||||
|
testing a bit easier.
|
||||||
|
|
||||||
|
I'm also not implementing the "config block" pattern in use for
|
||||||
|
Documents, because I think the UX is weird and I'm hoping to change
|
||||||
|
everything to use kwargs in a 2.0 release, anyway.
|
||||||
|
---
|
||||||
|
ext/nokogiri/xml_relax_ng.c | 39 ++++++++++++++++++--------
|
||||||
|
ext/nokogiri/xml_schema.c | 46 +++++++++++++++++++++++--------
|
||||||
|
lib/nokogiri/xml/parse_options.rb | 2 ++
|
||||||
|
lib/nokogiri/xml/relax_ng.rb | 4 +--
|
||||||
|
lib/nokogiri/xml/schema.rb | 10 ++++---
|
||||||
|
5 files changed, 72 insertions(+), 29 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/ext/nokogiri/xml_relax_ng.c b/ext/nokogiri/xml_relax_ng.c
|
||||||
|
index e17b11a..f361d27 100644
|
||||||
|
--- a/ext/nokogiri/xml_relax_ng.c
|
||||||
|
+++ b/ext/nokogiri/xml_relax_ng.c
|
||||||
|
@@ -53,16 +53,24 @@ static VALUE validate_document(VALUE self, VALUE document)
|
||||||
|
*
|
||||||
|
* Create a new RelaxNG from the contents of +string+
|
||||||
|
*/
|
||||||
|
-static VALUE read_memory(VALUE klass, VALUE content)
|
||||||
|
+static VALUE read_memory(int argc, VALUE *argv, VALUE klass)
|
||||||
|
{
|
||||||
|
- xmlRelaxNGParserCtxtPtr ctx = xmlRelaxNGNewMemParserCtxt(
|
||||||
|
- (const char *)StringValuePtr(content),
|
||||||
|
- (int)RSTRING_LEN(content)
|
||||||
|
- );
|
||||||
|
+ VALUE content;
|
||||||
|
+ VALUE parse_options;
|
||||||
|
+ xmlRelaxNGParserCtxtPtr ctx;
|
||||||
|
xmlRelaxNGPtr schema;
|
||||||
|
- VALUE errors = rb_ary_new();
|
||||||
|
+ VALUE errors;
|
||||||
|
VALUE rb_schema;
|
||||||
|
+ int scanned_args = 0;
|
||||||
|
+
|
||||||
|
+ scanned_args = rb_scan_args(argc, argv, "11", &content, &parse_options);
|
||||||
|
+ if (scanned_args == 1) {
|
||||||
|
+ parse_options = rb_const_get(rb_const_get(mNokogiriXml, rb_intern("ParseOptions")), rb_intern("DEFAULT_SCHEMA"));
|
||||||
|
+ }
|
||||||
|
|
||||||
|
+ ctx = xmlRelaxNGNewMemParserCtxt((const char *)StringValuePtr(content), (int)RSTRING_LEN(content));
|
||||||
|
+
|
||||||
|
+ errors = rb_ary_new();
|
||||||
|
xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
|
||||||
|
|
||||||
|
#ifdef HAVE_XMLRELAXNGSETPARSERSTRUCTUREDERRORS
|
||||||
|
@@ -90,6 +98,7 @@ static VALUE read_memory(VALUE klass, VALUE content)
|
||||||
|
|
||||||
|
rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
|
||||||
|
rb_iv_set(rb_schema, "@errors", errors);
|
||||||
|
+ rb_iv_set(rb_schema, "@parse_options", parse_options);
|
||||||
|
|
||||||
|
return rb_schema;
|
||||||
|
}
|
||||||
|
@@ -100,18 +109,25 @@ static VALUE read_memory(VALUE klass, VALUE content)
|
||||||
|
*
|
||||||
|
* Create a new RelaxNG schema from the Nokogiri::XML::Document +doc+
|
||||||
|
*/
|
||||||
|
-static VALUE from_document(VALUE klass, VALUE document)
|
||||||
|
+static VALUE from_document(int argc, VALUE *argv, VALUE klass)
|
||||||
|
{
|
||||||
|
+ VALUE document;
|
||||||
|
+ VALUE parse_options;
|
||||||
|
xmlDocPtr doc;
|
||||||
|
xmlRelaxNGParserCtxtPtr ctx;
|
||||||
|
xmlRelaxNGPtr schema;
|
||||||
|
VALUE errors;
|
||||||
|
VALUE rb_schema;
|
||||||
|
+ int scanned_args = 0;
|
||||||
|
+
|
||||||
|
+ scanned_args = rb_scan_args(argc, argv, "11", &document, &parse_options);
|
||||||
|
|
||||||
|
Data_Get_Struct(document, xmlDoc, doc);
|
||||||
|
+ doc = doc->doc; /* In case someone passes us a node. ugh. */
|
||||||
|
|
||||||
|
- /* In case someone passes us a node. ugh. */
|
||||||
|
- doc = doc->doc;
|
||||||
|
+ if (scanned_args == 1) {
|
||||||
|
+ parse_options = rb_const_get(rb_const_get(mNokogiriXml, rb_intern("ParseOptions")), rb_intern("DEFAULT_SCHEMA"));
|
||||||
|
+ }
|
||||||
|
|
||||||
|
ctx = xmlRelaxNGNewDocParserCtxt(doc);
|
||||||
|
|
||||||
|
@@ -142,6 +158,7 @@ static VALUE from_document(VALUE klass, VALUE document)
|
||||||
|
|
||||||
|
rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
|
||||||
|
rb_iv_set(rb_schema, "@errors", errors);
|
||||||
|
+ rb_iv_set(rb_schema, "@parse_options", parse_options);
|
||||||
|
|
||||||
|
return rb_schema;
|
||||||
|
}
|
||||||
|
@@ -155,7 +172,7 @@ void init_xml_relax_ng()
|
||||||
|
|
||||||
|
cNokogiriXmlRelaxNG = klass;
|
||||||
|
|
||||||
|
- rb_define_singleton_method(klass, "read_memory", read_memory, 1);
|
||||||
|
- rb_define_singleton_method(klass, "from_document", from_document, 1);
|
||||||
|
+ rb_define_singleton_method(klass, "read_memory", read_memory, -1);
|
||||||
|
+ rb_define_singleton_method(klass, "from_document", from_document, -1);
|
||||||
|
rb_define_private_method(klass, "validate_document", validate_document, 1);
|
||||||
|
}
|
||||||
|
diff --git a/ext/nokogiri/xml_schema.c b/ext/nokogiri/xml_schema.c
|
||||||
|
index 439f721..ea7c3d3 100644
|
||||||
|
--- a/ext/nokogiri/xml_schema.c
|
||||||
|
+++ b/ext/nokogiri/xml_schema.c
|
||||||
|
@@ -93,15 +93,26 @@ static VALUE validate_file(VALUE self, VALUE rb_filename)
|
||||||
|
*
|
||||||
|
* Create a new Schema from the contents of +string+
|
||||||
|
*/
|
||||||
|
-static VALUE read_memory(VALUE klass, VALUE content)
|
||||||
|
+static VALUE read_memory(int argc, VALUE *argv, VALUE klass)
|
||||||
|
{
|
||||||
|
+ VALUE content;
|
||||||
|
+ VALUE parse_options;
|
||||||
|
+ int parse_options_int;
|
||||||
|
+ xmlSchemaParserCtxtPtr ctx;
|
||||||
|
xmlSchemaPtr schema;
|
||||||
|
- xmlSchemaParserCtxtPtr ctx = xmlSchemaNewMemParserCtxt(
|
||||||
|
- (const char *)StringValuePtr(content),
|
||||||
|
- (int)RSTRING_LEN(content)
|
||||||
|
- );
|
||||||
|
+ VALUE errors;
|
||||||
|
VALUE rb_schema;
|
||||||
|
- VALUE errors = rb_ary_new();
|
||||||
|
+ int scanned_args = 0;
|
||||||
|
+
|
||||||
|
+ scanned_args = rb_scan_args(argc, argv, "11", &content, &parse_options);
|
||||||
|
+ if (scanned_args == 1) {
|
||||||
|
+ parse_options = rb_const_get(rb_const_get(mNokogiriXml, rb_intern("ParseOptions")), rb_intern("DEFAULT_SCHEMA"));
|
||||||
|
+ }
|
||||||
|
+ parse_options_int = (int)NUM2INT(rb_funcall(parse_options, rb_intern("to_i"), 0));
|
||||||
|
+
|
||||||
|
+ ctx = xmlSchemaNewMemParserCtxt((const char *)StringValuePtr(content), (int)RSTRING_LEN(content));
|
||||||
|
+
|
||||||
|
+ errors = rb_ary_new();
|
||||||
|
xmlSetStructuredErrorFunc((void *)errors, Nokogiri_error_array_pusher);
|
||||||
|
|
||||||
|
#ifdef HAVE_XMLSCHEMASETPARSERSTRUCTUREDERRORS
|
||||||
|
@@ -109,7 +120,7 @@ static VALUE read_memory(VALUE klass, VALUE content)
|
||||||
|
ctx,
|
||||||
|
Nokogiri_error_array_pusher,
|
||||||
|
(void *)errors
|
||||||
|
- );
|
||||||
|
+ );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
schema = xmlSchemaParse(ctx);
|
||||||
|
@@ -129,6 +140,7 @@ static VALUE read_memory(VALUE klass, VALUE content)
|
||||||
|
|
||||||
|
rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
|
||||||
|
rb_iv_set(rb_schema, "@errors", errors);
|
||||||
|
+ rb_iv_set(rb_schema, "@parse_options", parse_options);
|
||||||
|
|
||||||
|
return rb_schema;
|
||||||
|
}
|
||||||
|
@@ -164,18 +176,27 @@ static int has_blank_nodes_p(VALUE cache)
|
||||||
|
*
|
||||||
|
* Create a new Schema from the Nokogiri::XML::Document +doc+
|
||||||
|
*/
|
||||||
|
-static VALUE from_document(VALUE klass, VALUE document)
|
||||||
|
+static VALUE from_document(int argc, VALUE *argv, VALUE klass)
|
||||||
|
{
|
||||||
|
+ VALUE document;
|
||||||
|
+ VALUE parse_options;
|
||||||
|
+ int parse_options_int;
|
||||||
|
xmlDocPtr doc;
|
||||||
|
xmlSchemaParserCtxtPtr ctx;
|
||||||
|
xmlSchemaPtr schema;
|
||||||
|
VALUE errors;
|
||||||
|
VALUE rb_schema;
|
||||||
|
+ int scanned_args = 0;
|
||||||
|
+
|
||||||
|
+ scanned_args = rb_scan_args(argc, argv, "11", &document, &parse_options);
|
||||||
|
|
||||||
|
Data_Get_Struct(document, xmlDoc, doc);
|
||||||
|
+ doc = doc->doc; /* In case someone passes us a node. ugh. */
|
||||||
|
|
||||||
|
- /* In case someone passes us a node. ugh. */
|
||||||
|
- doc = doc->doc;
|
||||||
|
+ if (scanned_args == 1) {
|
||||||
|
+ parse_options = rb_const_get(rb_const_get(mNokogiriXml, rb_intern("ParseOptions")), rb_intern("DEFAULT_SCHEMA"));
|
||||||
|
+ }
|
||||||
|
+ parse_options_int = (int)NUM2INT(rb_funcall(parse_options, rb_intern("to_i"), 0));
|
||||||
|
|
||||||
|
if (has_blank_nodes_p(DOC_NODE_CACHE(doc))) {
|
||||||
|
rb_raise(rb_eArgError, "Creating a schema from a document that has blank nodes exposed to Ruby is dangerous");
|
||||||
|
@@ -211,6 +232,7 @@ static VALUE from_document(VALUE klass, VALUE document)
|
||||||
|
|
||||||
|
rb_schema = Data_Wrap_Struct(klass, 0, dealloc, schema);
|
||||||
|
rb_iv_set(rb_schema, "@errors", errors);
|
||||||
|
+ rb_iv_set(rb_schema, "@parse_options", parse_options);
|
||||||
|
|
||||||
|
return rb_schema;
|
||||||
|
|
||||||
|
@@ -226,8 +248,8 @@ void init_xml_schema()
|
||||||
|
|
||||||
|
cNokogiriXmlSchema = klass;
|
||||||
|
|
||||||
|
- rb_define_singleton_method(klass, "read_memory", read_memory, 1);
|
||||||
|
- rb_define_singleton_method(klass, "from_document", from_document, 1);
|
||||||
|
+ rb_define_singleton_method(klass, "read_memory", read_memory, -1);
|
||||||
|
+ rb_define_singleton_method(klass, "from_document", from_document, -1);
|
||||||
|
|
||||||
|
rb_define_private_method(klass, "validate_document", validate_document, 1);
|
||||||
|
rb_define_private_method(klass, "validate_file", validate_file, 1);
|
||||||
|
diff --git a/lib/nokogiri/xml/parse_options.rb b/lib/nokogiri/xml/parse_options.rb
|
||||||
|
index 8969578..c6d3d1c 100644
|
||||||
|
--- a/lib/nokogiri/xml/parse_options.rb
|
||||||
|
+++ b/lib/nokogiri/xml/parse_options.rb
|
||||||
|
@@ -72,6 +72,8 @@ module Nokogiri
|
||||||
|
DEFAULT_XML = RECOVER | NONET
|
||||||
|
# the default options used for parsing HTML documents
|
||||||
|
DEFAULT_HTML = RECOVER | NOERROR | NOWARNING | NONET
|
||||||
|
+ # the default options used for parsing XML schemas
|
||||||
|
+ DEFAULT_SCHEMA = NONET
|
||||||
|
|
||||||
|
attr_accessor :options
|
||||||
|
def initialize options = STRICT
|
||||||
|
diff --git a/lib/nokogiri/xml/relax_ng.rb b/lib/nokogiri/xml/relax_ng.rb
|
||||||
|
index 5a645a4..79bc30c 100644
|
||||||
|
--- a/lib/nokogiri/xml/relax_ng.rb
|
||||||
|
+++ b/lib/nokogiri/xml/relax_ng.rb
|
||||||
|
@@ -4,8 +4,8 @@ module Nokogiri
|
||||||
|
###
|
||||||
|
# Create a new Nokogiri::XML::RelaxNG document from +string_or_io+.
|
||||||
|
# See Nokogiri::XML::RelaxNG for an example.
|
||||||
|
- def RelaxNG string_or_io
|
||||||
|
- RelaxNG.new(string_or_io)
|
||||||
|
+ def RelaxNG(string_or_io, options = ParseOptions::DEFAULT_SCHEMA)
|
||||||
|
+ RelaxNG.new(string_or_io, options)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
diff --git a/lib/nokogiri/xml/schema.rb b/lib/nokogiri/xml/schema.rb
|
||||||
|
index 65a7bcd..a88f69c 100644
|
||||||
|
--- a/lib/nokogiri/xml/schema.rb
|
||||||
|
+++ b/lib/nokogiri/xml/schema.rb
|
||||||
|
@@ -4,8 +4,8 @@ module Nokogiri
|
||||||
|
###
|
||||||
|
# Create a new Nokogiri::XML::Schema object using a +string_or_io+
|
||||||
|
# object.
|
||||||
|
- def Schema string_or_io
|
||||||
|
- Schema.new(string_or_io)
|
||||||
|
+ def Schema(string_or_io, options = ParseOptions::DEFAULT_SCHEMA)
|
||||||
|
+ Schema.new(string_or_io, options)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@@ -29,12 +29,14 @@ module Nokogiri
|
||||||
|
class Schema
|
||||||
|
# Errors while parsing the schema file
|
||||||
|
attr_accessor :errors
|
||||||
|
+ # The Nokogiri::XML::ParseOptions used to parse the schema
|
||||||
|
+ attr_accessor :parse_options
|
||||||
|
|
||||||
|
###
|
||||||
|
# Create a new Nokogiri::XML::Schema object using a +string_or_io+
|
||||||
|
# object.
|
||||||
|
- def self.new string_or_io
|
||||||
|
- from_document Nokogiri::XML(string_or_io)
|
||||||
|
+ def self.new string_or_io, options = ParseOptions::DEFAULT_SCHEMA
|
||||||
|
+ from_document(Nokogiri::XML(string_or_io), options)
|
||||||
|
end
|
||||||
|
|
||||||
|
###
|
||||||
|
--
|
||||||
|
2.23.0
|
||||||
|
|
||||||
684
CVE-2021-41098-1.patch
Normal file
684
CVE-2021-41098-1.patch
Normal file
@ -0,0 +1,684 @@
|
|||||||
|
From 412f4e3a396dd36677ca202df96aa36656f9c800 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Mike Dalessio <mike.dalessio@gmail.com>
|
||||||
|
Date: Fri, 24 Sep 2021 14:13:39 -0400
|
||||||
|
Subject: [PATCH] refactor(jruby): handle errors more consistently
|
||||||
|
|
||||||
|
NokogiriErrorHandler stores RubyException but also accepts (and
|
||||||
|
type-converts) Exception and RaiseException.
|
||||||
|
|
||||||
|
NokgiriHandler uses NokogiriErrorHandler under the hood.
|
||||||
|
|
||||||
|
NokogiriErrorHandler classes use addError consistently everywhere.
|
||||||
|
---
|
||||||
|
ext/java/nokogiri/XmlSaxParserContext.java | 106 +++++-------------
|
||||||
|
ext/java/nokogiri/XmlSaxPushParser.java | 42 +++----
|
||||||
|
.../internals/NokogiriEntityResolver.java | 2 +-
|
||||||
|
.../internals/NokogiriErrorHandler.java | 37 ++++--
|
||||||
|
.../nokogiri/internals/NokogiriHandler.java | 26 +----
|
||||||
|
.../NokogiriNonStrictErrorHandler.java | 17 +--
|
||||||
|
...okogiriNonStrictErrorHandler4NekoHtml.java | 18 +--
|
||||||
|
.../internals/NokogiriStrictErrorHandler.java | 13 ++-
|
||||||
|
.../internals/XmlDomParserContext.java | 27 ++---
|
||||||
|
9 files changed, 115 insertions(+), 173 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/ext/java/nokogiri/XmlSaxParserContext.java b/ext/java/nokogiri/XmlSaxParserContext.java
|
||||||
|
index 5537619..5727a10 100644
|
||||||
|
--- a/ext/java/nokogiri/XmlSaxParserContext.java
|
||||||
|
+++ b/ext/java/nokogiri/XmlSaxParserContext.java
|
||||||
|
@@ -32,33 +32,23 @@
|
||||||
|
|
||||||
|
package nokogiri;
|
||||||
|
|
||||||
|
-import static org.jruby.runtime.Helpers.invoke;
|
||||||
|
-
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
-import nokogiri.internals.NokogiriHandler;
|
||||||
|
-import nokogiri.internals.NokogiriHelpers;
|
||||||
|
-import nokogiri.internals.ParserContext;
|
||||||
|
-import nokogiri.internals.XmlSaxParser;
|
||||||
|
+import static org.jruby.runtime.Helpers.invoke;
|
||||||
|
|
||||||
|
+import nokogiri.internals.*;
|
||||||
|
import org.apache.xerces.parsers.AbstractSAXParser;
|
||||||
|
import org.jruby.Ruby;
|
||||||
|
import org.jruby.RubyClass;
|
||||||
|
import org.jruby.RubyFixnum;
|
||||||
|
-import org.jruby.RubyModule;
|
||||||
|
-import org.jruby.RubyObjectAdapter;
|
||||||
|
import org.jruby.anno.JRubyClass;
|
||||||
|
import org.jruby.anno.JRubyMethod;
|
||||||
|
import org.jruby.exceptions.RaiseException;
|
||||||
|
-import org.jruby.javasupport.JavaEmbedUtils;
|
||||||
|
+import org.jruby.runtime.Helpers;
|
||||||
|
import org.jruby.runtime.ThreadContext;
|
||||||
|
import org.jruby.runtime.builtin.IRubyObject;
|
||||||
|
-import org.xml.sax.ContentHandler;
|
||||||
|
-import org.xml.sax.ErrorHandler;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
-import org.xml.sax.SAXNotRecognizedException;
|
||||||
|
-import org.xml.sax.SAXNotSupportedException;
|
||||||
|
import org.xml.sax.SAXParseException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
@@ -82,6 +72,7 @@ public class XmlSaxParserContext extends ParserContext {
|
||||||
|
protected AbstractSAXParser parser;
|
||||||
|
|
||||||
|
protected NokogiriHandler handler;
|
||||||
|
+ protected NokogiriErrorHandler errorHandler;
|
||||||
|
private boolean replaceEntities = true;
|
||||||
|
private boolean recovery = false;
|
||||||
|
|
||||||
|
@@ -179,24 +170,11 @@ public class XmlSaxParserContext extends ParserContext {
|
||||||
|
return (XmlSaxParserContext) NokogiriService.XML_SAXPARSER_CONTEXT_ALLOCATOR.allocate(runtime, klazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
- /**
|
||||||
|
- * Set a property of the underlying parser.
|
||||||
|
- */
|
||||||
|
- protected void setProperty(String key, Object val)
|
||||||
|
- throws SAXNotRecognizedException, SAXNotSupportedException {
|
||||||
|
- parser.setProperty(key, val);
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- protected void setContentHandler(ContentHandler handler) {
|
||||||
|
- parser.setContentHandler(handler);
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- protected void setErrorHandler(ErrorHandler handler) {
|
||||||
|
- parser.setErrorHandler(handler);
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
public final NokogiriHandler getNokogiriHandler() { return handler; }
|
||||||
|
|
||||||
|
+ public final NokogiriErrorHandler
|
||||||
|
+ getNokogiriErrorHandler() { return errorHandler; }
|
||||||
|
+
|
||||||
|
/**
|
||||||
|
* Perform any initialization prior to parsing with the handler
|
||||||
|
* <code>handlerRuby</code>. Convenience hook for subclasses.
|
||||||
|
@@ -221,6 +199,17 @@ public class XmlSaxParserContext extends ParserContext {
|
||||||
|
parser.parse(getInputSource());
|
||||||
|
}
|
||||||
|
|
||||||
|
+ protected static Options
|
||||||
|
+ defaultParseOptions(ThreadContext context)
|
||||||
|
+ {
|
||||||
|
+ return new ParserContext.Options(
|
||||||
|
+ RubyFixnum.fix2long(Helpers.invoke(context,
|
||||||
|
+ ((RubyClass)context.getRuntime().getClassFromPath("Nokogiri::XML::ParseOptions"))
|
||||||
|
+ .getConstant("DEFAULT_XML"),
|
||||||
|
+ "to_i"))
|
||||||
|
+ );
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
@JRubyMethod
|
||||||
|
public IRubyObject parse_with(ThreadContext context, IRubyObject handlerRuby) {
|
||||||
|
final Ruby runtime = context.getRuntime();
|
||||||
|
@@ -229,14 +218,18 @@ public class XmlSaxParserContext extends ParserContext {
|
||||||
|
throw runtime.newArgumentError("argument must respond_to document");
|
||||||
|
}
|
||||||
|
|
||||||
|
- NokogiriHandler handler = this.handler = new NokogiriHandler(runtime, handlerRuby);
|
||||||
|
- preParse(runtime, handlerRuby, handler);
|
||||||
|
+ /* TODO: how should we pass in parse options? */
|
||||||
|
+ ParserContext.Options options = defaultParseOptions(context);
|
||||||
|
+
|
||||||
|
+ errorHandler = new NokogiriStrictErrorHandler(runtime, options.noError, options.noWarning);
|
||||||
|
+ handler = new NokogiriHandler(runtime, handlerRuby, errorHandler);
|
||||||
|
|
||||||
|
- setContentHandler(handler);
|
||||||
|
- setErrorHandler(handler);
|
||||||
|
+ preParse(runtime, handlerRuby, handler);
|
||||||
|
+ parser.setContentHandler(handler);
|
||||||
|
+ parser.setErrorHandler(handler);
|
||||||
|
|
||||||
|
try{
|
||||||
|
- setProperty("http://xml.org/sax/properties/lexical-handler", handler);
|
||||||
|
+ parser.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
throw runtime.newRuntimeError("Problem while creating XML SAX Parser: " + ex.toString());
|
||||||
|
@@ -269,8 +262,6 @@ public class XmlSaxParserContext extends ParserContext {
|
||||||
|
|
||||||
|
postParse(runtime, handlerRuby, handler);
|
||||||
|
|
||||||
|
- //maybeTrimLeadingAndTrailingWhitespace(context, handlerRuby);
|
||||||
|
-
|
||||||
|
return runtime.getNil();
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -310,48 +301,6 @@ public class XmlSaxParserContext extends ParserContext {
|
||||||
|
return context.runtime.newBoolean(recovery);
|
||||||
|
}
|
||||||
|
|
||||||
|
- /**
|
||||||
|
- * If the handler's document is a FragmentHandler, attempt to trim
|
||||||
|
- * leading and trailing whitespace.
|
||||||
|
- *
|
||||||
|
- * This is a bit hackish and depends heavily on the internals of
|
||||||
|
- * FragmentHandler.
|
||||||
|
- */
|
||||||
|
- protected void maybeTrimLeadingAndTrailingWhitespace(ThreadContext context, IRubyObject parser) {
|
||||||
|
- RubyObjectAdapter adapter = JavaEmbedUtils.newObjectAdapter();
|
||||||
|
- RubyModule mod = context.getRuntime().getClassFromPath("Nokogiri::XML::FragmentHandler");
|
||||||
|
-
|
||||||
|
- IRubyObject handler = adapter.getInstanceVariable(parser, "@document");
|
||||||
|
- if (handler == null || handler.isNil() || !adapter.isKindOf(handler, mod))
|
||||||
|
- return;
|
||||||
|
- IRubyObject stack = adapter.getInstanceVariable(handler, "@stack");
|
||||||
|
- if (stack == null || stack.isNil())
|
||||||
|
- return;
|
||||||
|
- // doc is finally a DocumentFragment whose nodes we can check
|
||||||
|
- IRubyObject doc = adapter.callMethod(stack, "first");
|
||||||
|
- if (doc == null || doc.isNil())
|
||||||
|
- return;
|
||||||
|
-
|
||||||
|
- IRubyObject children;
|
||||||
|
-
|
||||||
|
- for (;;) {
|
||||||
|
- children = adapter.callMethod(doc, "children");
|
||||||
|
- IRubyObject first = adapter.callMethod(children, "first");
|
||||||
|
- if (NokogiriHelpers.isBlank(first)) adapter.callMethod(first, "unlink");
|
||||||
|
- else break;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- for (;;) {
|
||||||
|
- children = adapter.callMethod(doc, "children");
|
||||||
|
- IRubyObject last = adapter.callMethod(children, "last");
|
||||||
|
- if (NokogiriHelpers.isBlank(last)) adapter.callMethod(last, "unlink");
|
||||||
|
- else break;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- // While we have a document, normalize it.
|
||||||
|
- ((XmlNode) doc).normalize();
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
@JRubyMethod(name="column")
|
||||||
|
public IRubyObject column(ThreadContext context) {
|
||||||
|
final Integer number = handler.getColumn();
|
||||||
|
@@ -365,5 +314,4 @@ public class XmlSaxParserContext extends ParserContext {
|
||||||
|
if (number == null) return context.getRuntime().getNil();
|
||||||
|
return RubyFixnum.newFixnum(context.getRuntime(), number.longValue());
|
||||||
|
}
|
||||||
|
-
|
||||||
|
}
|
||||||
|
diff --git a/ext/java/nokogiri/XmlSaxPushParser.java b/ext/java/nokogiri/XmlSaxPushParser.java
|
||||||
|
index 8e65b92..b1b65a9 100644
|
||||||
|
--- a/ext/java/nokogiri/XmlSaxPushParser.java
|
||||||
|
+++ b/ext/java/nokogiri/XmlSaxPushParser.java
|
||||||
|
@@ -32,21 +32,10 @@
|
||||||
|
|
||||||
|
package nokogiri;
|
||||||
|
|
||||||
|
-import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
|
||||||
|
-import static org.jruby.runtime.Helpers.invoke;
|
||||||
|
-
|
||||||
|
-import java.io.ByteArrayInputStream;
|
||||||
|
-import java.io.IOException;
|
||||||
|
-import java.io.InputStream;
|
||||||
|
-import java.util.concurrent.ExecutionException;
|
||||||
|
-import java.util.concurrent.ExecutorService;
|
||||||
|
-import java.util.concurrent.Executors;
|
||||||
|
-import java.util.concurrent.Future;
|
||||||
|
-import java.util.concurrent.FutureTask;
|
||||||
|
-import java.util.concurrent.ThreadFactory;
|
||||||
|
-
|
||||||
|
+import nokogiri.internals.*;
|
||||||
|
import org.jruby.Ruby;
|
||||||
|
import org.jruby.RubyClass;
|
||||||
|
+import org.jruby.RubyException;
|
||||||
|
import org.jruby.RubyObject;
|
||||||
|
import org.jruby.anno.JRubyClass;
|
||||||
|
import org.jruby.anno.JRubyMethod;
|
||||||
|
@@ -54,11 +43,14 @@ import org.jruby.exceptions.RaiseException;
|
||||||
|
import org.jruby.runtime.ThreadContext;
|
||||||
|
import org.jruby.runtime.builtin.IRubyObject;
|
||||||
|
|
||||||
|
-import nokogiri.internals.ClosedStreamException;
|
||||||
|
-import nokogiri.internals.NokogiriBlockingQueueInputStream;
|
||||||
|
-import nokogiri.internals.NokogiriHandler;
|
||||||
|
-import nokogiri.internals.NokogiriHelpers;
|
||||||
|
-import nokogiri.internals.ParserContext;
|
||||||
|
+import java.io.ByteArrayInputStream;
|
||||||
|
+import java.io.IOException;
|
||||||
|
+import java.io.InputStream;
|
||||||
|
+import java.util.List;
|
||||||
|
+import java.util.concurrent.*;
|
||||||
|
+
|
||||||
|
+import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
|
||||||
|
+import static org.jruby.runtime.Helpers.invoke;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for Nokogiri::XML::SAX::PushParser
|
||||||
|
@@ -173,7 +165,8 @@ public class XmlSaxPushParser extends RubyObject {
|
||||||
|
|
||||||
|
if (!options.recover && parserTask.getErrorCount() > errorCount0) {
|
||||||
|
terminateTask(context.runtime);
|
||||||
|
- throw ex = parserTask.getLastError();
|
||||||
|
+ ex = parserTask.getLastError().toThrowable();
|
||||||
|
+ throw ex;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
@@ -273,14 +266,13 @@ public class XmlSaxPushParser extends RubyObject {
|
||||||
|
|
||||||
|
synchronized final int getErrorCount() {
|
||||||
|
// check for null because thread may not have started yet
|
||||||
|
- if (parser.getNokogiriHandler() == null) return 0;
|
||||||
|
- return parser.getNokogiriHandler().getErrorCount();
|
||||||
|
+ if (parser.getNokogiriErrorHandler() == null) { return 0; }
|
||||||
|
+ return parser.getNokogiriErrorHandler().getErrors().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
- synchronized final RaiseException getLastError() {
|
||||||
|
- return parser.getNokogiriHandler().getLastError();
|
||||||
|
+ synchronized final RubyException getLastError() {
|
||||||
|
+ List<RubyException> errors = parser.getNokogiriErrorHandler().getErrors();
|
||||||
|
+ return errors.get(errors.size() - 1);
|
||||||
|
}
|
||||||
|
-
|
||||||
|
}
|
||||||
|
-
|
||||||
|
}
|
||||||
|
diff --git a/ext/java/nokogiri/internals/NokogiriEntityResolver.java b/ext/java/nokogiri/internals/NokogiriEntityResolver.java
|
||||||
|
index d97da66..48942d0 100644
|
||||||
|
--- a/ext/java/nokogiri/internals/NokogiriEntityResolver.java
|
||||||
|
+++ b/ext/java/nokogiri/internals/NokogiriEntityResolver.java
|
||||||
|
@@ -68,7 +68,7 @@ public class NokogiriEntityResolver implements EntityResolver2 {
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addError(String errorMessage) {
|
||||||
|
- if (handler != null) handler.errors.add(new Exception(errorMessage));
|
||||||
|
+ if (handler != null) { handler.addError(new Exception(errorMessage)); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
diff --git a/ext/java/nokogiri/internals/NokogiriErrorHandler.java b/ext/java/nokogiri/internals/NokogiriErrorHandler.java
|
||||||
|
index 7980107..13b1725 100644
|
||||||
|
--- a/ext/java/nokogiri/internals/NokogiriErrorHandler.java
|
||||||
|
+++ b/ext/java/nokogiri/internals/NokogiriErrorHandler.java
|
||||||
|
@@ -32,12 +32,16 @@
|
||||||
|
|
||||||
|
package nokogiri.internals;
|
||||||
|
|
||||||
|
-import java.util.ArrayList;
|
||||||
|
-import java.util.List;
|
||||||
|
-
|
||||||
|
+import nokogiri.XmlSyntaxError;
|
||||||
|
import org.apache.xerces.xni.parser.XMLErrorHandler;
|
||||||
|
+import org.jruby.Ruby;
|
||||||
|
+import org.jruby.RubyException;
|
||||||
|
+import org.jruby.exceptions.RaiseException;
|
||||||
|
import org.xml.sax.ErrorHandler;
|
||||||
|
|
||||||
|
+import java.util.ArrayList;
|
||||||
|
+import java.util.List;
|
||||||
|
+
|
||||||
|
/**
|
||||||
|
* Super class of error handlers.
|
||||||
|
*
|
||||||
|
@@ -48,19 +52,36 @@ import org.xml.sax.ErrorHandler;
|
||||||
|
* @author Yoko Harada <yokolet@gmail.com>
|
||||||
|
*/
|
||||||
|
public abstract class NokogiriErrorHandler implements ErrorHandler, XMLErrorHandler {
|
||||||
|
- protected final List<Exception> errors;
|
||||||
|
+ private final Ruby runtime;
|
||||||
|
+ protected final List<RubyException> errors;
|
||||||
|
protected boolean noerror;
|
||||||
|
protected boolean nowarning;
|
||||||
|
|
||||||
|
- public NokogiriErrorHandler(boolean noerror, boolean nowarning) {
|
||||||
|
- this.errors = new ArrayList<Exception>(4);
|
||||||
|
+ public NokogiriErrorHandler(Ruby runtime, boolean noerror, boolean nowarning)
|
||||||
|
+ this.runtime = runtime;
|
||||||
|
+ this.errors = new ArrayList<RubyException>(4);
|
||||||
|
this.noerror = noerror;
|
||||||
|
this.nowarning = nowarning;
|
||||||
|
}
|
||||||
|
|
||||||
|
- List<Exception> getErrors() { return errors; }
|
||||||
|
+ public List<RubyException> getErrors() { return errors; }
|
||||||
|
|
||||||
|
- public void addError(Exception ex) { errors.add(ex); }
|
||||||
|
+ public void addError(Exception ex)
|
||||||
|
+ {
|
||||||
|
+ addError(XmlSyntaxError.createXMLSyntaxError(runtime, ex));
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public void
|
||||||
|
+ addError(RubyException ex)
|
||||||
|
+ {
|
||||||
|
+ errors.add(ex);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public void
|
||||||
|
+ addError(RaiseException ex)
|
||||||
|
+ {
|
||||||
|
+ addError(ex.getException());
|
||||||
|
+ }
|
||||||
|
|
||||||
|
protected boolean usesNekoHtml(String domain) {
|
||||||
|
return "http://cyberneko.org/html".equals(domain);
|
||||||
|
diff --git a/ext/java/nokogiri/internals/NokogiriHandler.java b/ext/java/nokogiri/internals/NokogiriHandler.java
|
||||||
|
index 5e34be1..2da4011 100644
|
||||||
|
--- a/ext/java/nokogiri/internals/NokogiriHandler.java
|
||||||
|
+++ b/ext/java/nokogiri/internals/NokogiriHandler.java
|
||||||
|
@@ -69,23 +69,17 @@ public class NokogiriHandler extends DefaultHandler2 implements XmlDeclHandler {
|
||||||
|
private final Ruby runtime;
|
||||||
|
private final RubyClass attrClass;
|
||||||
|
private final IRubyObject object;
|
||||||
|
-
|
||||||
|
- /**
|
||||||
|
- * Stores parse errors with the most-recent error last.
|
||||||
|
- *
|
||||||
|
- * TODO: should these be stored in the document 'errors' array?
|
||||||
|
- * Currently only string messages are stored there.
|
||||||
|
- */
|
||||||
|
- private final LinkedList<RaiseException> errors = new LinkedList<RaiseException>();
|
||||||
|
+ private NokogiriErrorHandler errorHandler;
|
||||||
|
|
||||||
|
private Locator locator;
|
||||||
|
private boolean needEmptyAttrCheck;
|
||||||
|
|
||||||
|
- public NokogiriHandler(Ruby runtime, IRubyObject object) {
|
||||||
|
+ public NokogiriHandler(Ruby runtime, IRubyObject object, NokogiriErrorHandler errorHandler) {
|
||||||
|
assert object != null;
|
||||||
|
this.runtime = runtime;
|
||||||
|
this.attrClass = (RubyClass) runtime.getClassFromPath("Nokogiri::XML::SAX::Parser::Attribute");
|
||||||
|
this.object = object;
|
||||||
|
+ this.errorHandler = errorHandler;
|
||||||
|
charactersBuilder = new StringBuilder();
|
||||||
|
String objectName = object.getMetaClass().getName();
|
||||||
|
if ("Nokogiri::HTML::SAX::Parser".equals(objectName)) needEmptyAttrCheck = true;
|
||||||
|
@@ -249,9 +243,9 @@ public class NokogiriHandler extends DefaultHandler2 implements XmlDeclHandler {
|
||||||
|
try {
|
||||||
|
final String msg = ex.getMessage();
|
||||||
|
call("error", runtime.newString(msg == null ? "" : msg));
|
||||||
|
- addError(new RaiseException(XmlSyntaxError.createError(runtime, ex), true));
|
||||||
|
+ errorHandler.addError(ex);
|
||||||
|
} catch( RaiseException e) {
|
||||||
|
- addError(e);
|
||||||
|
+ errorHandler.addError(e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -272,16 +266,8 @@ public class NokogiriHandler extends DefaultHandler2 implements XmlDeclHandler {
|
||||||
|
call("warning", runtime.newString(msg == null ? "" : msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
- protected synchronized void addError(RaiseException e) {
|
||||||
|
- errors.add(e);
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
public synchronized int getErrorCount() {
|
||||||
|
- return errors.size();
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- public synchronized RaiseException getLastError() {
|
||||||
|
- return errors.getLast();
|
||||||
|
+ return errorHandler.getErrors().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void call(String methodName) {
|
||||||
|
diff --git a/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java b/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java
|
||||||
|
index 15b622c..f49e13d 100644
|
||||||
|
--- a/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java
|
||||||
|
+++ b/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java
|
||||||
|
@@ -33,6 +33,7 @@
|
||||||
|
package nokogiri.internals;
|
||||||
|
|
||||||
|
import org.apache.xerces.xni.parser.XMLParseException;
|
||||||
|
+import org.jruby.Ruby;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
import org.xml.sax.SAXParseException;
|
||||||
|
|
||||||
|
@@ -43,16 +44,16 @@ import org.xml.sax.SAXParseException;
|
||||||
|
* @author Yoko Harada <yokolet@gmail.com>
|
||||||
|
*/
|
||||||
|
public class NokogiriNonStrictErrorHandler extends NokogiriErrorHandler{
|
||||||
|
- public NokogiriNonStrictErrorHandler(boolean noerror, boolean nowarning) {
|
||||||
|
- super(noerror, nowarning);
|
||||||
|
+ public NokogiriNonStrictErrorHandler(Ruby runtime, boolean noerror, boolean nowarning) {
|
||||||
|
+ super(runtime, noerror, nowarning);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void warning(SAXParseException ex) throws SAXException {
|
||||||
|
- errors.add(ex);
|
||||||
|
+ addError(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void error(SAXParseException ex) throws SAXException {
|
||||||
|
- errors.add(ex);
|
||||||
|
+ addError(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fatalError(SAXParseException ex) throws SAXException {
|
||||||
|
@@ -61,7 +62,7 @@ public class NokogiriNonStrictErrorHandler extends NokogiriErrorHandler{
|
||||||
|
// found in the prolog, instead it will keep calling this method and we'll
|
||||||
|
// keep inserting the error in the document errors array until we run
|
||||||
|
// out of memory
|
||||||
|
- errors.add(ex);
|
||||||
|
+ addError(ex);
|
||||||
|
String message = ex.getMessage();
|
||||||
|
|
||||||
|
// The problem with Xerces is that some errors will cause the
|
||||||
|
@@ -74,15 +75,15 @@ public class NokogiriNonStrictErrorHandler extends NokogiriErrorHandler{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void error(String domain, String key, XMLParseException e) {
|
||||||
|
- errors.add(e);
|
||||||
|
+ addError(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fatalError(String domain, String key, XMLParseException e) {
|
||||||
|
- errors.add(e);
|
||||||
|
+ addError(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void warning(String domain, String key, XMLParseException e) {
|
||||||
|
- errors.add(e);
|
||||||
|
+ addError(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
diff --git a/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java b/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java
|
||||||
|
index 011af24..a2c6b33 100644
|
||||||
|
--- a/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java
|
||||||
|
+++ b/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java
|
||||||
|
@@ -33,6 +33,7 @@
|
||||||
|
package nokogiri.internals;
|
||||||
|
|
||||||
|
import org.apache.xerces.xni.parser.XMLParseException;
|
||||||
|
+import org.jruby.Ruby;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
import org.xml.sax.SAXParseException;
|
||||||
|
|
||||||
|
@@ -50,12 +51,13 @@ import org.xml.sax.SAXParseException;
|
||||||
|
*/
|
||||||
|
public class NokogiriNonStrictErrorHandler4NekoHtml extends NokogiriErrorHandler {
|
||||||
|
|
||||||
|
- public NokogiriNonStrictErrorHandler4NekoHtml(boolean nowarning) {
|
||||||
|
- super(false, nowarning);
|
||||||
|
+ public NokogiriNonStrictErrorHandler4NekoHtml(Ruby runtime, boolean nowarning) {
|
||||||
|
+ super(runtime, false, nowarning);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NokogiriNonStrictErrorHandler4NekoHtml(boolean noerror, boolean nowarning) {
|
||||||
|
- super(noerror, nowarning);
|
||||||
|
+ public NokogiriNonStrictErrorHandler4NekoHtml(Ruby runtime, boolean noerror, boolean nowarning) {
|
||||||
|
+ super(runtime, noerror, nowarning);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void warning(SAXParseException ex) throws SAXException {
|
||||||
|
@@ -63,11 +65,11 @@ public class NokogiriNonStrictErrorHandler4NekoHtml extends NokogiriErrorHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
public void error(SAXParseException ex) throws SAXException {
|
||||||
|
- errors.add(ex);
|
||||||
|
+ addError(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fatalError(SAXParseException ex) throws SAXException {
|
||||||
|
- errors.add(ex);
|
||||||
|
+ addError(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@@ -83,7 +85,7 @@ public class NokogiriNonStrictErrorHandler4NekoHtml extends NokogiriErrorHandler
|
||||||
|
* @param e Exception.
|
||||||
|
*/
|
||||||
|
public void error(String domain, String key, XMLParseException e) {
|
||||||
|
- errors.add(e);
|
||||||
|
+ addError(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@@ -99,7 +101,7 @@ public class NokogiriNonStrictErrorHandler4NekoHtml extends NokogiriErrorHandler
|
||||||
|
* @param e Exception.
|
||||||
|
*/
|
||||||
|
public void fatalError(String domain, String key, XMLParseException e) {
|
||||||
|
- errors.add(e);
|
||||||
|
+ addError(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@@ -115,7 +117,7 @@ public class NokogiriNonStrictErrorHandler4NekoHtml extends NokogiriErrorHandler
|
||||||
|
* @param e Exception.
|
||||||
|
*/
|
||||||
|
public void warning(String domain, String key, XMLParseException e) {
|
||||||
|
- errors.add(e);
|
||||||
|
+ addError(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
diff --git a/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java b/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java
|
||||||
|
index 10315fa..fbf9787 100644
|
||||||
|
--- a/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java
|
||||||
|
+++ b/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java
|
||||||
|
@@ -33,6 +33,7 @@
|
||||||
|
package nokogiri.internals;
|
||||||
|
|
||||||
|
import org.apache.xerces.xni.parser.XMLParseException;
|
||||||
|
+import org.jruby.Ruby;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
import org.xml.sax.SAXParseException;
|
||||||
|
|
||||||
|
@@ -44,18 +45,18 @@ import org.xml.sax.SAXParseException;
|
||||||
|
* @author Yoko Harada <yokolet@gmail.com>
|
||||||
|
*/
|
||||||
|
public class NokogiriStrictErrorHandler extends NokogiriErrorHandler {
|
||||||
|
- public NokogiriStrictErrorHandler(boolean noerror, boolean nowarning) {
|
||||||
|
- super(noerror, nowarning);
|
||||||
|
+ public NokogiriStrictErrorHandler(Ruby runtime, boolean noerror, boolean nowarning) {
|
||||||
|
+ super(runtime, noerror, nowarning);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void warning(SAXParseException spex) throws SAXException {
|
||||||
|
if (!nowarning) throw spex;
|
||||||
|
- else errors.add(spex);
|
||||||
|
+ else { addError(spex); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void error(SAXParseException spex) throws SAXException {
|
||||||
|
if (!noerror) throw spex;
|
||||||
|
- else errors.add(spex);
|
||||||
|
+ else { addError(spex); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fatalError(SAXParseException spex) throws SAXException {
|
||||||
|
@@ -64,7 +65,7 @@ public class NokogiriStrictErrorHandler extends NokogiriErrorHandler {
|
||||||
|
|
||||||
|
public void error(String domain, String key, XMLParseException e) throws XMLParseException {
|
||||||
|
if (!noerror) throw e;
|
||||||
|
- else errors.add(e);
|
||||||
|
+ else { addError(e); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fatalError(String domain, String key, XMLParseException e) throws XMLParseException {
|
||||||
|
@@ -73,6 +74,6 @@ public class NokogiriStrictErrorHandler extends NokogiriErrorHandler {
|
||||||
|
|
||||||
|
public void warning(String domain, String key, XMLParseException e) throws XMLParseException {
|
||||||
|
if (!nowarning) throw e;
|
||||||
|
- if (!usesNekoHtml(domain)) errors.add(e);
|
||||||
|
+ if (!usesNekoHtml(domain)) { addError(e); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
diff --git a/ext/java/nokogiri/internals/XmlDomParserContext.java b/ext/java/nokogiri/internals/XmlDomParserContext.java
|
||||||
|
index 89af2bc..839399b 100644
|
||||||
|
--- a/ext/java/nokogiri/internals/XmlDomParserContext.java
|
||||||
|
+++ b/ext/java/nokogiri/internals/XmlDomParserContext.java
|
||||||
|
@@ -32,23 +32,17 @@
|
||||||
|
|
||||||
|
package nokogiri.internals;
|
||||||
|
|
||||||
|
-import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
|
||||||
|
-import static nokogiri.internals.NokogiriHelpers.isBlank;
|
||||||
|
-
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
-import nokogiri.NokogiriService;
|
||||||
|
+import static nokogiri.internals.NokogiriHelpers.isBlank;
|
||||||
|
+
|
||||||
|
import nokogiri.XmlDocument;
|
||||||
|
import nokogiri.XmlDtd;
|
||||||
|
import nokogiri.XmlSyntaxError;
|
||||||
|
-
|
||||||
|
import org.apache.xerces.parsers.DOMParser;
|
||||||
|
-import org.jruby.Ruby;
|
||||||
|
-import org.jruby.RubyArray;
|
||||||
|
-import org.jruby.RubyClass;
|
||||||
|
-import org.jruby.RubyFixnum;
|
||||||
|
+import org.jruby.*;
|
||||||
|
import org.jruby.exceptions.RaiseException;
|
||||||
|
import org.jruby.runtime.ThreadContext;
|
||||||
|
import org.jruby.runtime.builtin.IRubyObject;
|
||||||
|
@@ -78,7 +72,6 @@ public class XmlDomParserContext extends ParserContext {
|
||||||
|
protected static final String FEATURE_NOT_EXPAND_ENTITY =
|
||||||
|
"http://apache.org/xml/features/dom/create-entity-ref-nodes";
|
||||||
|
protected static final String FEATURE_VALIDATION = "http://xml.org/sax/features/validation";
|
||||||
|
- private static final String XINCLUDE_FEATURE_ID = "http://apache.org/xml/features/xinclude";
|
||||||
|
private static final String SECURITY_MANAGER = "http://apache.org/xml/properties/security-manager";
|
||||||
|
|
||||||
|
protected ParserContext.Options options;
|
||||||
|
@@ -96,15 +89,15 @@ public class XmlDomParserContext extends ParserContext {
|
||||||
|
this.options = new ParserContext.Options(RubyFixnum.fix2long(options));
|
||||||
|
java_encoding = NokogiriHelpers.getValidEncoding(runtime, encoding);
|
||||||
|
ruby_encoding = encoding;
|
||||||
|
- initErrorHandler();
|
||||||
|
+ initErrorHandler(runtime);
|
||||||
|
initParser(runtime);
|
||||||
|
}
|
||||||
|
|
||||||
|
- protected void initErrorHandler() {
|
||||||
|
+ protected void initErrorHandler(Ruby runtime) {
|
||||||
|
if (options.recover) {
|
||||||
|
- errorHandler = new NokogiriNonStrictErrorHandler(options.noError, options.noWarning);
|
||||||
|
+ errorHandler = new NokogiriNonStrictErrorHandler(runtime, options.noError, options.noWarning);
|
||||||
|
} else {
|
||||||
|
- errorHandler = new NokogiriStrictErrorHandler(options.noError, options.noWarning);
|
||||||
|
+ errorHandler = new NokogiriStrictErrorHandler(runtime, options.noError, options.noWarning);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -176,12 +169,10 @@ public class XmlDomParserContext extends ParserContext {
|
||||||
|
|
||||||
|
public static RubyArray mapErrors(ThreadContext context, NokogiriErrorHandler errorHandler) {
|
||||||
|
final Ruby runtime = context.runtime;
|
||||||
|
- final List<Exception> errors = errorHandler.getErrors();
|
||||||
|
+ final List<RubyException> errors = errorHandler.getErrors();
|
||||||
|
final IRubyObject[] errorsAry = new IRubyObject[errors.size()];
|
||||||
|
for (int i = 0; i < errors.size(); i++) {
|
||||||
|
- XmlSyntaxError xmlSyntaxError = XmlSyntaxError.createXMLSyntaxError(runtime);
|
||||||
|
- xmlSyntaxError.setException(errors.get(i));
|
||||||
|
- errorsAry[i] = xmlSyntaxError;
|
||||||
|
+ errorsAry[i] = errors.get(i);
|
||||||
|
}
|
||||||
|
return runtime.newArrayNoCopy(errorsAry);
|
||||||
|
}
|
||||||
|
--
|
||||||
|
2.27.0
|
||||||
|
|
||||||
28
CVE-2021-41098-2.patch
Normal file
28
CVE-2021-41098-2.patch
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
From 382860304b2efbf837cb3fcbbe806c81c27bf6b1 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Mike Dalessio <mike.dalessio@gmail.com>
|
||||||
|
Date: Fri, 24 Sep 2021 14:15:26 -0400
|
||||||
|
Subject: [PATCH] fix(jruby): SAX parser uses an entity resolver
|
||||||
|
|
||||||
|
to avoid XXE injections.
|
||||||
|
|
||||||
|
This behavior now matches the CRuby implementation.
|
||||||
|
---
|
||||||
|
ext/java/nokogiri/XmlSaxParserContext.java | 1 +
|
||||||
|
test/xml/sax/test_parser.rb | 33 ++++++++++++++++++++++
|
||||||
|
2 files changed, 34 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/ext/java/nokogiri/XmlSaxParserContext.java b/ext/java/nokogiri/XmlSaxParserContext.java
|
||||||
|
index 5727a10..e614ce9 100644
|
||||||
|
--- a/ext/java/nokogiri/XmlSaxParserContext.java
|
||||||
|
+++ b/ext/java/nokogiri/XmlSaxParserContext.java
|
||||||
|
@@ -227,6 +227,7 @@ public class XmlSaxParserContext extends ParserContext {
|
||||||
|
preParse(runtime, handlerRuby, handler);
|
||||||
|
parser.setContentHandler(handler);
|
||||||
|
parser.setErrorHandler(handler);
|
||||||
|
+ parser.setEntityResolver(new NokogiriEntityResolver(runtime, errorHandler, options));
|
||||||
|
|
||||||
|
try{
|
||||||
|
parser.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
|
||||||
|
--
|
||||||
|
2.27.0
|
||||||
|
|
||||||
38
fix-test-node-fail.patch
Normal file
38
fix-test-node-fail.patch
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
From 462d84a3dee286c75ca3c9185b48f0f7827a9d5f Mon Sep 17 00:00:00 2001
|
||||||
|
From: wk333 <13474090681@163.com>
|
||||||
|
Date: Thu, 6 Jan 2022 04:17:38 +0800
|
||||||
|
Subject: [PATCH 1/1] fix test node fail
|
||||||
|
|
||||||
|
---
|
||||||
|
test/xml/test_node.rb | 15 ---------------
|
||||||
|
1 file changed, 15 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/test/xml/test_node.rb b/test/xml/test_node.rb
|
||||||
|
index 4cd8292..707fa5a 100644
|
||||||
|
--- a/test/xml/test_node.rb
|
||||||
|
+++ b/test/xml/test_node.rb
|
||||||
|
@@ -1193,21 +1193,6 @@ EOXML
|
||||||
|
assert_nil set[4].attributes['x'].namespace
|
||||||
|
end
|
||||||
|
|
||||||
|
- if Nokogiri.uses_libxml?
|
||||||
|
- def test_namespace_without_an_href_on_html_node
|
||||||
|
- # because microsoft word's HTML formatting does this. ick.
|
||||||
|
- xml = Nokogiri::HTML.parse <<-EOF
|
||||||
|
- <div><o:p>foo</o:p></div>
|
||||||
|
- EOF
|
||||||
|
-
|
||||||
|
- assert_not_nil(node = xml.at('p'))
|
||||||
|
-
|
||||||
|
- assert_equal 1, node.namespaces.keys.size
|
||||||
|
- assert node.namespaces.has_key?('xmlns:o')
|
||||||
|
- assert_nil node.namespaces['xmlns:o']
|
||||||
|
- end
|
||||||
|
- end
|
||||||
|
-
|
||||||
|
def test_line
|
||||||
|
xml = Nokogiri::XML(<<-eoxml)
|
||||||
|
<root>
|
||||||
|
--
|
||||||
|
2.27.0
|
||||||
|
|
||||||
33
fix-test-push-parser-fail.patch
Normal file
33
fix-test-push-parser-fail.patch
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
From ee33011cdcb3018314e4d23abbcbd17470a48290 Mon Sep 17 00:00:00 2001
|
||||||
|
From: baizg1107 <preloyalwhite@163.com>
|
||||||
|
Date: Thu, 9 Dec 2021 19:47:10 +0800
|
||||||
|
Subject: [PATCH] fix test push parser fail
|
||||||
|
|
||||||
|
---
|
||||||
|
test/html/sax/test_push_parser.rb | 10 ----------
|
||||||
|
1 file changed, 10 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/test/html/sax/test_push_parser.rb b/test/html/sax/test_push_parser.rb
|
||||||
|
index a3939d0..9536114 100644
|
||||||
|
--- a/test/html/sax/test_push_parser.rb
|
||||||
|
+++ b/test/html/sax/test_push_parser.rb
|
||||||
|
@@ -71,16 +71,6 @@ module Nokogiri
|
||||||
|
assert_equal 0, @parser.options
|
||||||
|
end
|
||||||
|
|
||||||
|
- def test_broken_encoding
|
||||||
|
- skip("ultra hard to fix for pure Java version") if Nokogiri.jruby?
|
||||||
|
- @parser.options |= XML::ParseOptions::RECOVER
|
||||||
|
- # This is ISO_8859-1:
|
||||||
|
- @parser.<< "<?xml version='1.0' encoding='UTF-8'?><r>Gau\337</r>"
|
||||||
|
- @parser.finish
|
||||||
|
- assert(@parser.document.errors.size >= 1)
|
||||||
|
- assert_equal "Gau\337", @parser.document.data.join
|
||||||
|
- assert_equal [["r"], ["body"], ["html"]], @parser.document.end_elements
|
||||||
|
- end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
--
|
||||||
|
2.27.0
|
||||||
|
|
||||||
BIN
nokogiri-1.10.5.gem
Normal file
BIN
nokogiri-1.10.5.gem
Normal file
Binary file not shown.
Binary file not shown.
@ -1,27 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
if [ $# -lt 2 ]
|
|
||||||
then
|
|
||||||
echo "$0 <name> <version>"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
set -x
|
|
||||||
set -e
|
|
||||||
|
|
||||||
CURRDIR=$(pwd)
|
|
||||||
|
|
||||||
TMPDIRPATH=$(mktemp -d /var/tmp/$1-tar-XXXXXX)
|
|
||||||
pushd $TMPDIRPATH
|
|
||||||
|
|
||||||
git clone https://github.com/sparklemotion/$1.git
|
|
||||||
pushd $1
|
|
||||||
git reset --hard v$2
|
|
||||||
popd
|
|
||||||
|
|
||||||
ln -sf $1 $1-$2
|
|
||||||
tar czf ${CURRDIR}/rubygem-$1-$2-full.tar.gz $1-$2/./
|
|
||||||
|
|
||||||
popd
|
|
||||||
|
|
||||||
rm -rf $TMPDIRPATH
|
|
||||||
Binary file not shown.
10
rubygem-nokogiri-1.6.6.4-shutdown-libxml2-warning.patch
Normal file
10
rubygem-nokogiri-1.6.6.4-shutdown-libxml2-warning.patch
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
--- nokogiri-1.6.6.4/./lib/nokogiri/version.rb.nowarn 2015-11-20 05:50:37.000000000 +0900
|
||||||
|
+++ nokogiri-1.6.6.4/./lib/nokogiri/version.rb 2015-12-11 14:32:04.151973080 +0900
|
||||||
|
@@ -34,6 +34,7 @@
|
||||||
|
end
|
||||||
|
|
||||||
|
def warnings
|
||||||
|
+ return []
|
||||||
|
return [] unless libxml2?
|
||||||
|
|
||||||
|
if compiled_parser_version != loaded_parser_version
|
||||||
@ -1,4 +1,4 @@
|
|||||||
%global mainver 1.13.7
|
%global mainver 1.10.5
|
||||||
%global mainrel 1
|
%global mainrel 1
|
||||||
%global prerpmver %(echo "%{?prever}" | sed -e 's|\\.||g')
|
%global prerpmver %(echo "%{?prever}" | sed -e 's|\\.||g')
|
||||||
%global gem_name nokogiri
|
%global gem_name nokogiri
|
||||||
@ -7,18 +7,22 @@
|
|||||||
Summary: An HTML, XML, SAX, and Reader parser
|
Summary: An HTML, XML, SAX, and Reader parser
|
||||||
Name: rubygem-%{gem_name}
|
Name: rubygem-%{gem_name}
|
||||||
Version: %{mainver}
|
Version: %{mainver}
|
||||||
Release: 2
|
Release: 4
|
||||||
License: MIT and Apache-2.0
|
License: MIT
|
||||||
URL: https://nokogiri.org
|
URL: https://nokogiri.org
|
||||||
Source0: https://rubygems.org/gems/%{gem_name}-%{mainver}%{?prever}.gem
|
Source0: https://rubygems.org/gems/%{gem_name}-%{mainver}%{?prever}.gem
|
||||||
Source1: rubygem-%{gem_name}-%{version}%{?prever}-full.tar.gz
|
Source1: https://github.com/sparklemotion/%{gem_name}/archive/v%{mainver}.tar.gz
|
||||||
|
# Shut down libxml2 version unmatching warning
|
||||||
|
Patch0: %{name}-1.6.6.4-shutdown-libxml2-warning.patch
|
||||||
|
Patch1: CVE-2020-26247-pre.patch
|
||||||
|
Patch2: CVE-2020-26247.patch
|
||||||
|
Patch3: CVE-2021-41098-1.patch
|
||||||
|
Patch4: CVE-2021-41098-2.patch
|
||||||
|
Patch5: fix-test-push-parser-fail.patch
|
||||||
|
Patch6: fix-test-node-fail.patch
|
||||||
BuildRequires: ruby(release) ruby(rubygems) rubygem(minitest) rubygems-devel
|
BuildRequires: ruby(release) ruby(rubygems) rubygem(minitest) rubygems-devel
|
||||||
BuildRequires: rubygem(did_you_mean)
|
|
||||||
Obsoletes: ruby-%{gem_name} <= 1.5.2-2
|
Obsoletes: ruby-%{gem_name} <= 1.5.2-2
|
||||||
BuildRequires: gcc libxml2-devel libxslt-devel ruby-devel glibc-all-langpacks rubygem(racc)
|
BuildRequires: gcc rubygem(pkg-config) libxml2-devel libxslt-devel ruby-devel
|
||||||
Requires: rubygem(racc)
|
|
||||||
|
|
||||||
%description
|
%description
|
||||||
Nokogiri parses and searches XML/HTML very quickly, and also has
|
Nokogiri parses and searches XML/HTML very quickly, and also has
|
||||||
correctly implemented CSS3 selector support as well as XPath support.
|
correctly implemented CSS3 selector support as well as XPath support.
|
||||||
@ -48,36 +52,38 @@ This package provides non-Gem support for %{gem_name}.
|
|||||||
%global version %{mainver}%{?prever}
|
%global version %{mainver}%{?prever}
|
||||||
|
|
||||||
%prep
|
%prep
|
||||||
%setup -q -n %{gem_name}-%{version} -a 1
|
%setup -q -T -c -a 1
|
||||||
mv ../%{gem_name}-%{version}.gemspec .
|
TOPDIR=$(pwd)
|
||||||
|
mkdir tmpunpackdir
|
||||||
|
pushd tmpunpackdir
|
||||||
|
gem unpack %{SOURCE0}
|
||||||
|
cd %{gem_name}-%{version}
|
||||||
|
%patch0 -p1
|
||||||
|
%patch1 -p1
|
||||||
|
%patch2 -p1
|
||||||
|
|
||||||
|
#The file exists only in the source code directory,not in the GEM.
|
||||||
|
cd $TOPDIR/%{gem_name}-%{version}
|
||||||
|
%patch3 -p1
|
||||||
|
%patch4 -p1
|
||||||
|
%patch5 -p1
|
||||||
|
%patch6 -p1
|
||||||
|
cd -
|
||||||
|
|
||||||
|
gem specification -l --ruby %{SOURCE0} > %{gem_name}.gemspec
|
||||||
sed -i \
|
sed -i \
|
||||||
-e 's|, "ports/archives/[^"][^"]*"||g' \
|
-e 's|, "ports/archives/[^"][^"]*"||g' \
|
||||||
-e 's|, "ports/patches/[^"][^"]*"||g' \
|
-e 's|, "ports/patches/[^"][^"]*"||g' \
|
||||||
%{gem_name}-%{version}.gemspec
|
%{gem_name}.gemspec
|
||||||
sed -i -e '\@mini_portile@d' %{gem_name}-%{version}.gemspec
|
sed -i -e '\@mini_portile@d' %{gem_name}.gemspec
|
||||||
sed -i \
|
LANG=C.UTF-8 gem build %{gem_name}.gemspec
|
||||||
ext/nokogiri/extconf.rb \
|
mv %{gem_name}-%{version}.gem $TOPDIR
|
||||||
-e "s@^\(def process_recipe.*\)\$@\1 ; return true@" \
|
popd
|
||||||
-e "s@^\(append_cppflags\).*gumbo.*\$@\1(\"-I$(pwd)/gumbo-parser/src\")@" \
|
rm -rf tmpunpackdir
|
||||||
-e "\@libs.*gumbo@s@File\.join.*@\"$(pwd)/gumbo-parser/src/libgumbo.a\"@" \
|
|
||||||
-e "\@LIBPATH.*gumbo@s|^\(.*\)\$|# \1|" \
|
|
||||||
%{nil}
|
|
||||||
sed -i \
|
|
||||||
gumbo-parser/src/char_ref.c \
|
|
||||||
-e '\@^#line [0-9]@s|^\(.*\)$|// \1|'
|
|
||||||
sed -i \
|
|
||||||
gumbo-parser/src/Makefile \
|
|
||||||
-e 's|^\(CFLAGS.*=.*\)$|\1 -fPIC|'
|
|
||||||
env LANG=C.UTF-8 gem build %{gem_name}-%{version}.gemspec
|
|
||||||
#CVE-2022-40303 https://gitlab.gnome.org/GNOME/libxml2/-/commit/c846986
|
|
||||||
sed -i 's/assert_predicate(handler.errors, :empty?)/assert_match(\/CData section too big\/, handler.errors.first)/g' nokogiri-1.13.7/test/xml/sax/test_parser.rb
|
|
||||||
|
|
||||||
%build
|
%build
|
||||||
|
mkdir -p ./%{gem_dir}
|
||||||
export NOKOGIRI_USE_SYSTEM_LIBRARIES=yes
|
export NOKOGIRI_USE_SYSTEM_LIBRARIES=yes
|
||||||
%set_build_flags
|
|
||||||
pushd gumbo-parser/src/
|
|
||||||
make libgumbo.a
|
|
||||||
popd
|
|
||||||
%gem_install
|
%gem_install
|
||||||
chmod 0644 .%{gem_dir}/cache/%{gem_name}-%{mainver}%{?prever}.gem
|
chmod 0644 .%{gem_dir}/cache/%{gem_name}-%{mainver}%{?prever}.gem
|
||||||
rm -f .%{gem_instdir}/lib/*.jar
|
rm -f .%{gem_instdir}/lib/*.jar
|
||||||
@ -86,7 +92,6 @@ rm -rf .%{gem_instdir}/ext/java
|
|||||||
%install
|
%install
|
||||||
mkdir -p %{buildroot}%{gem_dir}
|
mkdir -p %{buildroot}%{gem_dir}
|
||||||
cp -a ./%{gem_dir}/* %{buildroot}%{gem_dir}
|
cp -a ./%{gem_dir}/* %{buildroot}%{gem_dir}
|
||||||
cp -a ./gumbo-parser %{buildroot}%{gem_instdir}/
|
|
||||||
find %{buildroot} -name \*.orig_\* | xargs rm -vf
|
find %{buildroot} -name \*.orig_\* | xargs rm -vf
|
||||||
mkdir -p %{buildroot}%{gem_extdir_mri}
|
mkdir -p %{buildroot}%{gem_extdir_mri}
|
||||||
cp -a ./%{gem_extdir_mri}/* %{buildroot}%{gem_extdir_mri}/
|
cp -a ./%{gem_extdir_mri}/* %{buildroot}%{gem_extdir_mri}/
|
||||||
@ -102,24 +107,17 @@ do
|
|||||||
chmod 0644 $f
|
chmod 0644 $f
|
||||||
done
|
done
|
||||||
cp -p %{gem_name}-%{version}/[A-Z]* %{buildroot}%{gem_instdir}/
|
cp -p %{gem_name}-%{version}/[A-Z]* %{buildroot}%{gem_instdir}/
|
||||||
pushd %{buildroot}%{gem_instdir}
|
rm -rf %{buildroot}%{gem_instdir}/ext/%{gem_name}/
|
||||||
rm -rf \
|
rm -rf %{buildroot}%{gem_instdir}/tmp/
|
||||||
Gemfile* \
|
rm -f %{buildroot}%{gem_instdir}/{.autotest,.require_paths,.gemtest,.travis.yml}
|
||||||
dependencies.yml \
|
rm -f %{buildroot}%{gem_instdir}/appveyor.yml
|
||||||
ext \
|
rm -f %{buildroot}%{gem_instdir}/.cross_rubies
|
||||||
*gemspec \
|
rm -f %{buildroot}%{gem_instdir}/{build_all,dependencies.yml,test_all}
|
||||||
patches \
|
rm -f %{buildroot}%{gem_instdir}/.editorconfig
|
||||||
ports \
|
rm -rf %{buildroot}%{gem_instdir}/suppressions/
|
||||||
%{nil}
|
rm -rf %{buildroot}%{gem_instdir}/patches/
|
||||||
pushd gumbo-parser
|
rm -f %{buildroot}%{gem_instdir}/{Rakefile,Gemfile*}
|
||||||
rm \
|
rm -f %{buildroot}%{gem_instdir}/Manifest.txt
|
||||||
Makefile \
|
|
||||||
%{nil}
|
|
||||||
find src -type f | \
|
|
||||||
grep -v README.md | \
|
|
||||||
xargs rm -f
|
|
||||||
popd
|
|
||||||
rm -f %{buildroot}%{gem_cache}
|
|
||||||
|
|
||||||
%check
|
%check
|
||||||
export TZ="Asia/Tokyo"
|
export TZ="Asia/Tokyo"
|
||||||
@ -128,11 +126,8 @@ cp -a %{gem_name}-%{version}/test/ ./%{gem_instdir}
|
|||||||
pushd ./%{gem_instdir}
|
pushd ./%{gem_instdir}
|
||||||
sed -i test/helper.rb \
|
sed -i test/helper.rb \
|
||||||
-e '\@require.*simplecov@,\@^end$@d'
|
-e '\@require.*simplecov@,\@^end$@d'
|
||||||
sed -i '/require..minitest.reporters./ s/^/#/' test/helper.rb
|
ruby \
|
||||||
sed -i '/Minitest::Reporters/ s/^/#/' test/helper.rb
|
-I.:lib:test:ext \
|
||||||
env \
|
|
||||||
RUBYLIB=".:lib:test:ext" \
|
|
||||||
ruby \
|
|
||||||
-e \
|
-e \
|
||||||
"require 'test/helper' ; Dir.glob('test/**/test_*.rb'){|f| require f}" || \
|
"require 'test/helper' ; Dir.glob('test/**/test_*.rb'){|f| require f}" || \
|
||||||
exit 1
|
exit 1
|
||||||
@ -144,40 +139,29 @@ done
|
|||||||
popd
|
popd
|
||||||
|
|
||||||
%files
|
%files
|
||||||
|
%defattr(-,root, root,-)
|
||||||
%{_bindir}/%{gem_name}
|
%{_bindir}/%{gem_name}
|
||||||
%{gem_extdir_mri}/
|
%{gem_extdir_mri}/
|
||||||
%dir %{gem_instdir}/
|
%dir %{gem_instdir}/
|
||||||
%doc %{gem_instdir}/[A-Z]*
|
%doc %{gem_instdir}/[A-Z]*
|
||||||
%{gem_instdir}/bin/
|
%{gem_instdir}/bin/
|
||||||
%{gem_instdir}/lib/
|
%{gem_instdir}/lib/
|
||||||
|
%exclude %{gem_dir}/cache/%{gem_name}-%{mainver}%{?prever}.gem
|
||||||
%dir %{gem_instdir}/gumbo-parser
|
|
||||||
%dir %{gem_instdir}/gumbo-parser/src
|
|
||||||
%doc %{gem_instdir}/gumbo-parser/[A-Z]*
|
|
||||||
%doc %{gem_instdir}/gumbo-parser/src/README.md
|
|
||||||
|
|
||||||
%{gem_dir}/specifications/%{gem_name}-%{mainver}%{?prever}.gemspec
|
%{gem_dir}/specifications/%{gem_name}-%{mainver}%{?prever}.gemspec
|
||||||
|
%if 0
|
||||||
|
|
||||||
|
%files jruby
|
||||||
|
%defattr(-,root,root,-)
|
||||||
|
%{gem_instdir}/ext/java/
|
||||||
|
%endif
|
||||||
|
|
||||||
%files doc
|
%files doc
|
||||||
%defattr(-,root,root,-)
|
%defattr(-,root,root,-)
|
||||||
|
%exclude %{gem_instdir}/tasks/
|
||||||
|
%exclude %{gem_instdir}/test/
|
||||||
%{gem_dir}/doc/%{gem_name}-%{mainver}%{?prever}/
|
%{gem_dir}/doc/%{gem_name}-%{mainver}%{?prever}/
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
* Fri Nov 11 2022 Ge Wang <wangge20@h-partners.com> - 1.13.7-2
|
|
||||||
- fix build failure due to libxml fixed CVE
|
|
||||||
|
|
||||||
* Thu Jul 14 2022 Ge Wang <wangge20@h-partners.com> - 1.13.7-1
|
|
||||||
- update to 1.13.7
|
|
||||||
|
|
||||||
* Sun Apr 24 2022 wangkai <wangkai385@h-partners.com> - 1.13.1-2
|
|
||||||
- Fix CVE-2022-24836
|
|
||||||
|
|
||||||
* Thu Mar 03 2022 jiangxinyu <jiangxinyu@kylinos.cn> - 1.13.1-1
|
|
||||||
- update to 1.13.1
|
|
||||||
|
|
||||||
* Fri Jan 07 2022 liyanan <liyanan32@huawei.com> - 1.10.5-5
|
|
||||||
- fix canonicalize already defined by glibc
|
|
||||||
|
|
||||||
* Fri Jan 07 2022 wangkai <wangkai385@huawei.com> - 1.10.5-4
|
* Fri Jan 07 2022 wangkai <wangkai385@huawei.com> - 1.10.5-4
|
||||||
- fix compile failed
|
- fix compile failed
|
||||||
|
|
||||||
|
|||||||
BIN
v1.10.5.tar.gz
Normal file
BIN
v1.10.5.tar.gz
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user