nokogiri 1.10.0 → 1.11.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of nokogiri might be problematic. Click here for more details.

Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -0
  3. data/LICENSE-DEPENDENCIES.md +1015 -947
  4. data/README.md +178 -90
  5. data/dependencies.yml +28 -26
  6. data/ext/nokogiri/depend +476 -357
  7. data/ext/nokogiri/extconf.rb +508 -354
  8. data/ext/nokogiri/html_document.c +79 -78
  9. data/ext/nokogiri/html_sax_parser_context.c +4 -2
  10. data/ext/nokogiri/html_sax_push_parser.c +14 -8
  11. data/ext/nokogiri/nokogiri.c +37 -40
  12. data/ext/nokogiri/nokogiri.h +26 -17
  13. data/ext/nokogiri/test_global_handlers.c +41 -0
  14. data/ext/nokogiri/xml_document.c +18 -4
  15. data/ext/nokogiri/xml_io.c +8 -6
  16. data/ext/nokogiri/xml_node.c +23 -6
  17. data/ext/nokogiri/xml_node_set.c +1 -1
  18. data/ext/nokogiri/xml_reader.c +6 -17
  19. data/ext/nokogiri/xml_relax_ng.c +29 -11
  20. data/ext/nokogiri/xml_sax_parser.c +2 -7
  21. data/ext/nokogiri/xml_sax_parser_context.c +4 -2
  22. data/ext/nokogiri/xml_sax_push_parser.c +2 -0
  23. data/ext/nokogiri/xml_schema.c +84 -13
  24. data/ext/nokogiri/xml_syntax_error.c +23 -0
  25. data/ext/nokogiri/xml_syntax_error.h +15 -3
  26. data/ext/nokogiri/xml_xpath_context.c +80 -4
  27. data/ext/nokogiri/xslt_stylesheet.c +2 -9
  28. data/lib/nokogiri.rb +22 -22
  29. data/lib/nokogiri/css.rb +1 -0
  30. data/lib/nokogiri/css/node.rb +1 -0
  31. data/lib/nokogiri/css/parser.rb +63 -62
  32. data/lib/nokogiri/css/parser.y +2 -2
  33. data/lib/nokogiri/css/parser_extras.rb +39 -36
  34. data/lib/nokogiri/css/syntax_error.rb +1 -0
  35. data/lib/nokogiri/css/tokenizer.rb +105 -103
  36. data/lib/nokogiri/css/xpath_visitor.rb +73 -43
  37. data/lib/nokogiri/decorators/slop.rb +1 -0
  38. data/lib/nokogiri/html.rb +1 -0
  39. data/lib/nokogiri/html/builder.rb +1 -0
  40. data/lib/nokogiri/html/document.rb +13 -26
  41. data/lib/nokogiri/html/document_fragment.rb +1 -0
  42. data/lib/nokogiri/html/element_description.rb +1 -0
  43. data/lib/nokogiri/html/element_description_defaults.rb +1 -0
  44. data/lib/nokogiri/html/entity_lookup.rb +1 -0
  45. data/lib/nokogiri/html/sax/parser.rb +1 -0
  46. data/lib/nokogiri/html/sax/parser_context.rb +1 -0
  47. data/lib/nokogiri/html/sax/push_parser.rb +1 -0
  48. data/lib/nokogiri/jruby/dependencies.rb +20 -0
  49. data/lib/nokogiri/syntax_error.rb +1 -0
  50. data/lib/nokogiri/version.rb +3 -109
  51. data/lib/nokogiri/version/constant.rb +5 -0
  52. data/lib/nokogiri/version/info.rb +182 -0
  53. data/lib/nokogiri/xml.rb +1 -0
  54. data/lib/nokogiri/xml/attr.rb +1 -0
  55. data/lib/nokogiri/xml/attribute_decl.rb +1 -0
  56. data/lib/nokogiri/xml/builder.rb +36 -32
  57. data/lib/nokogiri/xml/cdata.rb +1 -0
  58. data/lib/nokogiri/xml/character_data.rb +1 -0
  59. data/lib/nokogiri/xml/document.rb +21 -16
  60. data/lib/nokogiri/xml/document_fragment.rb +5 -6
  61. data/lib/nokogiri/xml/dtd.rb +1 -0
  62. data/lib/nokogiri/xml/element_content.rb +1 -0
  63. data/lib/nokogiri/xml/element_decl.rb +1 -0
  64. data/lib/nokogiri/xml/entity_decl.rb +1 -0
  65. data/lib/nokogiri/xml/entity_reference.rb +1 -0
  66. data/lib/nokogiri/xml/namespace.rb +1 -0
  67. data/lib/nokogiri/xml/node.rb +588 -250
  68. data/lib/nokogiri/xml/node/save_options.rb +1 -0
  69. data/lib/nokogiri/xml/node_set.rb +43 -8
  70. data/lib/nokogiri/xml/notation.rb +1 -0
  71. data/lib/nokogiri/xml/parse_options.rb +10 -3
  72. data/lib/nokogiri/xml/pp.rb +1 -0
  73. data/lib/nokogiri/xml/pp/character_data.rb +1 -0
  74. data/lib/nokogiri/xml/pp/node.rb +1 -0
  75. data/lib/nokogiri/xml/processing_instruction.rb +1 -0
  76. data/lib/nokogiri/xml/reader.rb +7 -3
  77. data/lib/nokogiri/xml/relax_ng.rb +7 -2
  78. data/lib/nokogiri/xml/sax.rb +1 -0
  79. data/lib/nokogiri/xml/sax/document.rb +1 -0
  80. data/lib/nokogiri/xml/sax/parser.rb +1 -0
  81. data/lib/nokogiri/xml/sax/parser_context.rb +1 -0
  82. data/lib/nokogiri/xml/sax/push_parser.rb +1 -0
  83. data/lib/nokogiri/xml/schema.rb +13 -4
  84. data/lib/nokogiri/xml/searchable.rb +25 -16
  85. data/lib/nokogiri/xml/syntax_error.rb +1 -0
  86. data/lib/nokogiri/xml/text.rb +1 -0
  87. data/lib/nokogiri/xml/xpath.rb +1 -0
  88. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -0
  89. data/lib/nokogiri/xml/xpath_context.rb +1 -0
  90. data/lib/nokogiri/xslt.rb +1 -0
  91. data/lib/nokogiri/xslt/stylesheet.rb +1 -0
  92. data/lib/xsd/xmlparser/nokogiri.rb +1 -0
  93. data/patches/libxml2/0002-Remove-script-macro-support.patch +40 -0
  94. data/patches/libxml2/0003-Update-entities-to-remove-handling-of-ssi.patch +44 -0
  95. data/patches/libxml2/0004-libxml2.la-is-in-top_builddir.patch +25 -0
  96. data/patches/libxml2/0005-Fix-infinite-loop-in-xmlStringLenDecodeEntities.patch +32 -0
  97. data/patches/libxml2/0006-htmlParseComment-treat-as-if-it-closed-the-comment.patch +73 -0
  98. data/patches/libxml2/0007-use-new-htmlParseLookupCommentEnd-to-find-comment-en.patch +103 -0
  99. data/patches/libxml2/0008-use-glibc-strlen.patch +53 -0
  100. data/patches/libxml2/0009-avoid-isnan-isinf.patch +81 -0
  101. data/ports/archives/libxml2-2.9.10.tar.gz +0 -0
  102. data/ports/archives/libxslt-1.1.34.tar.gz +0 -0
  103. metadata +106 -99
  104. data/ports/archives/libxml2-2.9.9.tar.gz +0 -0
  105. data/ports/archives/libxslt-1.1.33.tar.gz +0 -0
@@ -1,6 +1,7 @@
1
1
  #include <html_document.h>
2
2
 
3
3
  static ID id_encoding_found;
4
+ static ID id_to_s;
4
5
 
5
6
  /*
6
7
  * call-seq:
@@ -8,19 +9,20 @@ static ID id_encoding_found;
8
9
  *
9
10
  * Create a new document
10
11
  */
11
- static VALUE new(int argc, VALUE *argv, VALUE klass)
12
+ static VALUE
13
+ rb_html_document_s_new(int argc, VALUE *argv, VALUE klass)
12
14
  {
13
15
  VALUE uri, external_id, rest, rb_doc;
14
16
  htmlDocPtr doc;
15
17
 
16
18
  rb_scan_args(argc, argv, "0*", &rest);
17
- uri = rb_ary_entry(rest, (long)0);
19
+ uri = rb_ary_entry(rest, (long)0);
18
20
  external_id = rb_ary_entry(rest, (long)1);
19
21
 
20
22
  doc = htmlNewDoc(
21
- RTEST(uri) ? (const xmlChar *)StringValueCStr(uri) : NULL,
22
- RTEST(external_id) ? (const xmlChar *)StringValueCStr(external_id) : NULL
23
- );
23
+ RTEST(uri) ? (const xmlChar *)StringValueCStr(uri) : NULL,
24
+ RTEST(external_id) ? (const xmlChar *)StringValueCStr(external_id) : NULL
25
+ );
24
26
  rb_doc = Nokogiri_wrap_xml_document(klass, doc);
25
27
  rb_obj_call_init(rb_doc, argc, argv);
26
28
  return rb_doc ;
@@ -33,60 +35,55 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
33
35
  * Read the HTML document from +io+ with given +url+, +encoding+,
34
36
  * and +options+. See Nokogiri::HTML.parse
35
37
  */
36
- static VALUE read_io( VALUE klass,
37
- VALUE io,
38
- VALUE url,
39
- VALUE encoding,
40
- VALUE options )
38
+ static VALUE
39
+ rb_html_document_s_read_io(VALUE klass, VALUE rb_io, VALUE rb_url, VALUE rb_encoding, VALUE rb_options)
41
40
  {
42
- const char * c_url = NIL_P(url) ? NULL : StringValueCStr(url);
43
- const char * c_enc = NIL_P(encoding) ? NULL : StringValueCStr(encoding);
44
- VALUE error_list = rb_ary_new();
45
- VALUE document;
46
- htmlDocPtr doc;
41
+ VALUE rb_doc;
42
+ VALUE rb_error_list = rb_ary_new();
43
+ htmlDocPtr c_doc;
44
+ const char *c_url = NIL_P(rb_url) ? NULL : StringValueCStr(rb_url);
45
+ const char *c_encoding = NIL_P(rb_encoding) ? NULL : StringValueCStr(rb_encoding);
46
+ int options = NUM2INT(rb_options);
47
+
48
+ xmlSetStructuredErrorFunc((void *)rb_error_list, Nokogiri_error_array_pusher);
49
+
50
+ c_doc = htmlReadIO(io_read_callback, io_close_callback, (void *)rb_io, c_url, c_encoding, options);
47
51
 
48
- xmlResetLastError();
49
- xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
50
-
51
- doc = htmlReadIO(
52
- io_read_callback,
53
- io_close_callback,
54
- (void *)io,
55
- c_url,
56
- c_enc,
57
- (int)NUM2INT(options)
58
- );
59
52
  xmlSetStructuredErrorFunc(NULL, NULL);
60
53
 
61
54
  /*
62
55
  * If EncodingFound has occurred in EncodingReader, make sure to do
63
56
  * a cleanup and propagate the error.
64
57
  */
65
- if (rb_respond_to(io, id_encoding_found)) {
66
- VALUE encoding_found = rb_funcall(io, id_encoding_found, 0);
58
+ if (rb_respond_to(rb_io, id_encoding_found)) {
59
+ VALUE encoding_found = rb_funcall(rb_io, id_encoding_found, 0);
67
60
  if (!NIL_P(encoding_found)) {
68
- xmlFreeDoc(doc);
61
+ xmlFreeDoc(c_doc);
69
62
  rb_exc_raise(encoding_found);
70
63
  }
71
64
  }
72
65
 
73
- if(doc == NULL) {
74
- xmlErrorPtr error;
66
+ if ((c_doc == NULL) || (!(options & XML_PARSE_RECOVER) && (RARRAY_LEN(rb_error_list) > 0))) {
67
+ VALUE rb_error ;
75
68
 
76
- xmlFreeDoc(doc);
69
+ xmlFreeDoc(c_doc);
77
70
 
78
- error = xmlGetLastError();
79
- if(error)
80
- rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
81
- else
71
+ rb_error = rb_ary_entry(rb_error_list, 0);
72
+ if (rb_error == Qnil) {
82
73
  rb_raise(rb_eRuntimeError, "Could not parse document");
74
+ } else {
75
+ VALUE exception_message = rb_funcall(rb_error, id_to_s, 0);
76
+ exception_message = rb_str_concat(rb_str_new2("Parser without recover option encountered error or warning: "),
77
+ exception_message);
78
+ rb_exc_raise(rb_class_new_instance(1, &exception_message, cNokogiriXmlSyntaxError));
79
+ }
83
80
 
84
81
  return Qnil;
85
82
  }
86
83
 
87
- document = Nokogiri_wrap_xml_document(klass, doc);
88
- rb_iv_set(document, "@errors", error_list);
89
- return document;
84
+ rb_doc = Nokogiri_wrap_xml_document(klass, c_doc);
85
+ rb_iv_set(rb_doc, "@errors", rb_error_list);
86
+ return rb_doc;
90
87
  }
91
88
 
92
89
  /*
@@ -96,43 +93,45 @@ static VALUE read_io( VALUE klass,
96
93
  * Read the HTML document contained in +string+ with given +url+, +encoding+,
97
94
  * and +options+. See Nokogiri::HTML.parse
98
95
  */
99
- static VALUE read_memory( VALUE klass,
100
- VALUE string,
101
- VALUE url,
102
- VALUE encoding,
103
- VALUE options )
96
+ static VALUE
97
+ rb_html_document_s_read_memory(VALUE klass, VALUE rb_html, VALUE rb_url, VALUE rb_encoding, VALUE rb_options)
104
98
  {
105
- const char * c_buffer = StringValuePtr(string);
106
- const char * c_url = NIL_P(url) ? NULL : StringValueCStr(url);
107
- const char * c_enc = NIL_P(encoding) ? NULL : StringValueCStr(encoding);
108
- int len = (int)RSTRING_LEN(string);
109
- VALUE error_list = rb_ary_new();
110
- VALUE document;
111
- htmlDocPtr doc;
99
+ VALUE rb_doc;
100
+ VALUE rb_error_list = rb_ary_new();
101
+ htmlDocPtr c_doc;
102
+ const char *c_buffer = StringValuePtr(rb_html);
103
+ const char *c_url = NIL_P(rb_url) ? NULL : StringValueCStr(rb_url);
104
+ const char *c_encoding = NIL_P(rb_encoding) ? NULL : StringValueCStr(rb_encoding);
105
+ int html_len = (int)RSTRING_LEN(rb_html);
106
+ int options = NUM2INT(rb_options);
112
107
 
113
- xmlResetLastError();
114
- xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
108
+ xmlSetStructuredErrorFunc((void *)rb_error_list, Nokogiri_error_array_pusher);
109
+
110
+ c_doc = htmlReadMemory(c_buffer, html_len, c_url, c_encoding, options);
115
111
 
116
- doc = htmlReadMemory(c_buffer, len, c_url, c_enc, (int)NUM2INT(options));
117
112
  xmlSetStructuredErrorFunc(NULL, NULL);
118
113
 
119
- if(doc == NULL) {
120
- xmlErrorPtr error;
114
+ if ((c_doc == NULL) || (!(options & XML_PARSE_RECOVER) && (RARRAY_LEN(rb_error_list) > 0))) {
115
+ VALUE rb_error ;
121
116
 
122
- xmlFreeDoc(doc);
117
+ xmlFreeDoc(c_doc);
123
118
 
124
- error = xmlGetLastError();
125
- if(error)
126
- rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
127
- else
119
+ rb_error = rb_ary_entry(rb_error_list, 0);
120
+ if (rb_error == Qnil) {
128
121
  rb_raise(rb_eRuntimeError, "Could not parse document");
122
+ } else {
123
+ VALUE exception_message = rb_funcall(rb_error, id_to_s, 0);
124
+ exception_message = rb_str_concat(rb_str_new2("Parser without recover option encountered error or warning: "),
125
+ exception_message);
126
+ rb_exc_raise(rb_class_new_instance(1, &exception_message, cNokogiriXmlSyntaxError));
127
+ }
129
128
 
130
129
  return Qnil;
131
130
  }
132
131
 
133
- document = Nokogiri_wrap_xml_document(klass, doc);
134
- rb_iv_set(document, "@errors", error_list);
135
- return document;
132
+ rb_doc = Nokogiri_wrap_xml_document(klass, c_doc);
133
+ rb_iv_set(rb_doc, "@errors", rb_error_list);
134
+ return rb_doc;
136
135
  }
137
136
 
138
137
  /*
@@ -141,7 +140,8 @@ static VALUE read_memory( VALUE klass,
141
140
  *
142
141
  * The type for this document
143
142
  */
144
- static VALUE type(VALUE self)
143
+ static VALUE
144
+ rb_html_document_type(VALUE self)
145
145
  {
146
146
  htmlDocPtr doc;
147
147
  Data_Get_Struct(self, xmlDoc, doc);
@@ -149,22 +149,23 @@ static VALUE type(VALUE self)
149
149
  }
150
150
 
151
151
  VALUE cNokogiriHtmlDocument ;
152
- void init_html_document()
153
- {
154
- VALUE nokogiri = rb_define_module("Nokogiri");
155
- VALUE html = rb_define_module_under(nokogiri, "HTML");
156
- VALUE xml = rb_define_module_under(nokogiri, "XML");
157
- VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
158
- VALUE xml_doc = rb_define_class_under(xml, "Document", node);
159
- VALUE klass = rb_define_class_under(html, "Document", xml_doc);
160
152
 
161
- cNokogiriHtmlDocument = klass;
153
+ void
154
+ init_html_document()
155
+ {
156
+ VALUE nokogiri = rb_define_module("Nokogiri");
157
+ VALUE nokogiri_xml = rb_define_module_under(nokogiri, "XML");
158
+ VALUE nokogiri_xml_node = rb_define_class_under(nokogiri_xml, "Node", rb_cObject);
159
+ VALUE nokogiri_xml_document = rb_define_class_under(nokogiri_xml, "Document", nokogiri_xml_node);
160
+ VALUE nokogiri_html = rb_define_module_under(nokogiri, "HTML");
161
+ cNokogiriHtmlDocument = rb_define_class_under(nokogiri_html, "Document", nokogiri_xml_document);
162
162
 
163
- rb_define_singleton_method(klass, "read_memory", read_memory, 4);
164
- rb_define_singleton_method(klass, "read_io", read_io, 4);
165
- rb_define_singleton_method(klass, "new", new, -1);
163
+ rb_define_singleton_method(cNokogiriHtmlDocument, "read_memory", rb_html_document_s_read_memory, 4);
164
+ rb_define_singleton_method(cNokogiriHtmlDocument, "read_io", rb_html_document_s_read_io, 4);
165
+ rb_define_singleton_method(cNokogiriHtmlDocument, "new", rb_html_document_s_new, -1);
166
166
 
167
- rb_define_method(klass, "type", type, 0);
167
+ rb_define_method(cNokogiriHtmlDocument, "type", rb_html_document_type, 0);
168
168
 
169
169
  id_encoding_found = rb_intern("encoding_found");
170
+ id_to_s = rb_intern("to_s");
170
171
  }
@@ -4,13 +4,13 @@ VALUE cNokogiriHtmlSaxParserContext ;
4
4
 
5
5
  static void deallocate(xmlParserCtxtPtr ctxt)
6
6
  {
7
- NOKOGIRI_DEBUG_START(handler);
7
+ NOKOGIRI_DEBUG_START(ctxt);
8
8
 
9
9
  ctxt->sax = NULL;
10
10
 
11
11
  htmlFreeParserCtxt(ctxt);
12
12
 
13
- NOKOGIRI_DEBUG_END(handler);
13
+ NOKOGIRI_DEBUG_END(ctxt);
14
14
  }
15
15
 
16
16
  static VALUE
@@ -92,6 +92,8 @@ parse_with(VALUE self, VALUE sax_handler)
92
92
  ctxt->sax = sax;
93
93
  ctxt->userData = (void *)NOKOGIRI_SAX_TUPLE_NEW(ctxt, sax_handler);
94
94
 
95
+ xmlSetStructuredErrorFunc(NULL, NULL);
96
+
95
97
  rb_ensure(parse_doc, (VALUE)ctxt, parse_doc_finalize, (VALUE)ctxt);
96
98
 
97
99
  return self;
@@ -9,9 +9,10 @@
9
9
  static VALUE native_write(VALUE self, VALUE _chunk, VALUE _last_chunk)
10
10
  {
11
11
  xmlParserCtxtPtr ctx;
12
- const char * chunk = NULL;
13
- int size = 0;
14
-
12
+ const char * chunk = NULL;
13
+ int size = 0;
14
+ int status = 0;
15
+ libxmlStructuredErrorHandlerState handler_state;
15
16
 
16
17
  Data_Get_Struct(self, xmlParserCtxt, ctx);
17
18
 
@@ -20,11 +21,16 @@ static VALUE native_write(VALUE self, VALUE _chunk, VALUE _last_chunk)
20
21
  size = (int)RSTRING_LEN(_chunk);
21
22
  }
22
23
 
23
- if(htmlParseChunk(ctx, chunk, size, Qtrue == _last_chunk ? 1 : 0)) {
24
- if (!(ctx->options & XML_PARSE_RECOVER)) {
25
- xmlErrorPtr e = xmlCtxtGetLastError(ctx);
26
- Nokogiri_error_raise(NULL, e);
27
- }
24
+ Nokogiri_structured_error_func_save_and_set(&handler_state, NULL, NULL);
25
+
26
+ status = htmlParseChunk(ctx, chunk, size, Qtrue == _last_chunk ? 1 : 0);
27
+
28
+ Nokogiri_structured_error_func_restore(&handler_state);
29
+
30
+ if ((status != 0) && !(ctx->options & XML_PARSE_RECOVER)) {
31
+ // TODO: there appear to be no tests for this block
32
+ xmlErrorPtr e = xmlCtxtGetLastError(ctx);
33
+ Nokogiri_error_raise(NULL, e);
28
34
  }
29
35
 
30
36
  return self;
@@ -1,5 +1,7 @@
1
1
  #include <nokogiri.h>
2
2
 
3
+ void init_test_global_handlers(); /* in lieu of test_global_handlers.h */
4
+
3
5
  VALUE mNokogiri ;
4
6
  VALUE mNokogiriXml ;
5
7
  VALUE mNokogiriHtml ;
@@ -7,12 +9,11 @@ VALUE mNokogiriXslt ;
7
9
  VALUE mNokogiriXmlSax ;
8
10
  VALUE mNokogiriHtmlSax ;
9
11
 
10
- #ifdef USE_INCLUDED_VASPRINTF
12
+ #ifndef HAVE_VASPRINTF
11
13
  /*
12
- * I srsly hate windows. it doesn't have vasprintf.
13
14
  * Thank you Geoffroy Couprie for this implementation of vasprintf!
14
15
  */
15
- int vasprintf (char **strp, const char *fmt, va_list ap)
16
+ int vasprintf(char **strp, const char *fmt, va_list ap)
16
17
  {
17
18
  /* Mingw32/64 have a broken vsnprintf implementation that fails when
18
19
  * using a zero-byte limit in order to retrieve the required size for malloc.
@@ -21,23 +22,15 @@ int vasprintf (char **strp, const char *fmt, va_list ap)
21
22
  char tmp[1];
22
23
  int len = vsnprintf (tmp, 1, fmt, ap) + 1;
23
24
  char *res = (char *)malloc((unsigned int)len);
24
- if (res == NULL)
25
- return -1;
25
+ if (res == NULL) {
26
+ return -1;
27
+ }
26
28
  *strp = res;
27
29
  return vsnprintf(res, (unsigned int)len, fmt, ap);
28
30
  }
29
31
  #endif
30
32
 
31
- void vasprintf_free (void *p)
32
- {
33
- free(p);
34
- }
35
-
36
- #ifdef HAVE_RUBY_UTIL_H
37
33
  #include "ruby/util.h"
38
- #else
39
- #include "util.h"
40
- #endif
41
34
 
42
35
  void nokogiri_root_node(xmlNodePtr node)
43
36
  {
@@ -45,7 +38,7 @@ void nokogiri_root_node(xmlNodePtr node)
45
38
  nokogiriTuplePtr tuple;
46
39
 
47
40
  doc = node->doc;
48
- if (doc->type == XML_DOCUMENT_FRAG_NODE) doc = doc->doc;
41
+ if (doc->type == XML_DOCUMENT_FRAG_NODE) { doc = doc->doc; }
49
42
  tuple = (nokogiriTuplePtr)doc->_private;
50
43
  st_insert(tuple->unlinkedNodes, (st_data_t)node, (st_data_t)node);
51
44
  }
@@ -54,7 +47,7 @@ void nokogiri_root_nsdef(xmlNsPtr ns, xmlDocPtr doc)
54
47
  {
55
48
  nokogiriTuplePtr tuple;
56
49
 
57
- if (doc->type == XML_DOCUMENT_FRAG_NODE) doc = doc->doc;
50
+ if (doc->type == XML_DOCUMENT_FRAG_NODE) { doc = doc->doc; }
58
51
  tuple = (nokogiriTuplePtr)doc->_private;
59
52
  st_insert(tuple->unlinkedNodes, (st_data_t)ns, (st_data_t)ns);
60
53
  }
@@ -62,10 +55,10 @@ void nokogiri_root_nsdef(xmlNsPtr ns, xmlDocPtr doc)
62
55
  void Init_nokogiri()
63
56
  {
64
57
  xmlMemSetup(
65
- (xmlFreeFunc)ruby_xfree,
66
- (xmlMallocFunc)ruby_xmalloc,
67
- (xmlReallocFunc)ruby_xrealloc,
68
- ruby_strdup
58
+ (xmlFreeFunc)ruby_xfree,
59
+ (xmlMallocFunc)ruby_xmalloc,
60
+ (xmlReallocFunc)ruby_xrealloc,
61
+ ruby_strdup
69
62
  );
70
63
 
71
64
  mNokogiri = rb_define_module("Nokogiri");
@@ -75,27 +68,26 @@ void Init_nokogiri()
75
68
  mNokogiriXmlSax = rb_define_module_under(mNokogiriXml, "SAX");
76
69
  mNokogiriHtmlSax = rb_define_module_under(mNokogiriHtml, "SAX");
77
70
 
78
- rb_const_set( mNokogiri,
79
- rb_intern("LIBXML_VERSION"),
80
- NOKOGIRI_STR_NEW2(LIBXML_DOTTED_VERSION)
81
- );
82
- rb_const_set( mNokogiri,
83
- rb_intern("LIBXML_PARSER_VERSION"),
84
- NOKOGIRI_STR_NEW2(xmlParserVersion)
85
- );
86
-
87
- #ifdef NOKOGIRI_USE_PACKAGED_LIBRARIES
88
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_USE_PACKAGED_LIBRARIES"), Qtrue);
89
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXML2_PATH"), NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXML2_PATH));
90
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXSLT_PATH"), NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXSLT_PATH));
91
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXML2_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXML2_PATCHES), " "));
92
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXSLT_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXSLT_PATCHES), " "));
71
+ rb_const_set(mNokogiri, rb_intern("LIBXML_COMPILED_VERSION"), NOKOGIRI_STR_NEW2(LIBXML_DOTTED_VERSION));
72
+ rb_const_set(mNokogiri, rb_intern("LIBXML_LOADED_VERSION"), NOKOGIRI_STR_NEW2(xmlParserVersion));
73
+
74
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_COMPILED_VERSION"), NOKOGIRI_STR_NEW2(LIBXSLT_DOTTED_VERSION));
75
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_LOADED_VERSION"), NOKOGIRI_STR_NEW2(xsltEngineVersion));
76
+
77
+ #ifdef NOKOGIRI_PACKAGED_LIBRARIES
78
+ rb_const_set(mNokogiri, rb_intern("PACKAGED_LIBRARIES"), Qtrue);
79
+ #ifdef NOKOGIRI_PRECOMPILED_LIBRARIES
80
+ rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qtrue);
81
+ #else
82
+ rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qfalse);
83
+ #endif
84
+ rb_const_set(mNokogiri, rb_intern("LIBXML2_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXML2_PATCHES), " "));
85
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_PATCHES"), rb_str_split(NOKOGIRI_STR_NEW2(NOKOGIRI_LIBXSLT_PATCHES), " "));
93
86
  #else
94
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_USE_PACKAGED_LIBRARIES"), Qfalse);
95
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXML2_PATH"), Qnil);
96
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXSLT_PATH"), Qnil);
97
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXML2_PATCHES"), Qnil);
98
- rb_const_set(mNokogiri, rb_intern("NOKOGIRI_LIBXSLT_PATCHES"), Qnil);
87
+ rb_const_set(mNokogiri, rb_intern("PACKAGED_LIBRARIES"), Qfalse);
88
+ rb_const_set(mNokogiri, rb_intern("PRECOMPILED_LIBRARIES"), Qfalse);
89
+ rb_const_set(mNokogiri, rb_intern("LIBXML2_PATCHES"), Qnil);
90
+ rb_const_set(mNokogiri, rb_intern("LIBXSLT_PATCHES"), Qnil);
99
91
  #endif
100
92
 
101
93
  #ifdef LIBXML_ICONV_ENABLED
@@ -104,6 +96,10 @@ void Init_nokogiri()
104
96
  rb_const_set(mNokogiri, rb_intern("LIBXML_ICONV_ENABLED"), Qfalse);
105
97
  #endif
106
98
 
99
+ #ifdef NOKOGIRI_OTHER_LIBRARY_VERSIONS
100
+ rb_const_set(mNokogiri, rb_intern("OTHER_LIBRARY_VERSIONS"), NOKOGIRI_STR_NEW2(NOKOGIRI_OTHER_LIBRARY_VERSIONS));
101
+ #endif
102
+
107
103
  xmlInitParser();
108
104
 
109
105
  init_xml_document();
@@ -138,4 +134,5 @@ void Init_nokogiri()
138
134
  init_xml_relax_ng();
139
135
  init_nokogiri_io();
140
136
  init_xml_encoding_handler();
137
+ init_test_global_handlers();
141
138
  }
@@ -1,20 +1,25 @@
1
1
  #ifndef NOKOGIRI_NATIVE
2
2
  #define NOKOGIRI_NATIVE
3
3
 
4
+ #if _MSC_VER
5
+ # ifndef WIN32_LEAN_AND_MEAN
6
+ # define WIN32_LEAN_AND_MEAN
7
+ # endif /* WIN32_LEAN_AND_MEAN */
8
+
9
+ # ifndef WIN32
10
+ # define WIN32
11
+ # endif /* WIN32 */
12
+
13
+ # include <winsock2.h>
14
+ # include <ws2tcpip.h>
15
+ # include <windows.h>
16
+ #endif
17
+
4
18
  #include <stdlib.h>
5
19
  #include <string.h>
6
20
  #include <assert.h>
7
21
  #include <stdarg.h>
8
-
9
- #ifdef USE_INCLUDED_VASPRINTF
10
- int vasprintf (char **strp, const char *fmt, va_list ap);
11
- #else
12
-
13
- #define _GNU_SOURCE
14
- # include <stdio.h>
15
- #undef _GNU_SOURCE
16
-
17
- #endif
22
+ #include <stdio.h>
18
23
 
19
24
  #include <libxml/parser.h>
20
25
  #include <libxml/entities.h>
@@ -29,7 +34,9 @@ int vasprintf (char **strp, const char *fmt, va_list ap);
29
34
  #include <libxml/relaxng.h>
30
35
  #include <libxml/xinclude.h>
31
36
  #include <libxslt/extensions.h>
37
+ #include <libxslt/xsltconfig.h>
32
38
  #include <libxml/c14n.h>
39
+
33
40
  #include <ruby.h>
34
41
  #include <ruby/st.h>
35
42
  #include <ruby/encoding.h>
@@ -93,25 +100,27 @@ extern VALUE mNokogiriHtml ;
93
100
  extern VALUE mNokogiriHtmlSax ;
94
101
  extern VALUE mNokogiriXslt ;
95
102
 
103
+ int vasprintf(char **strp, const char *fmt, va_list ap);
104
+
96
105
  void nokogiri_root_node(xmlNodePtr);
97
106
  void nokogiri_root_nsdef(xmlNsPtr, xmlDocPtr);
98
107
 
99
108
  #ifdef DEBUG
100
109
 
101
- #define NOKOGIRI_DEBUG_START(p) if (getenv("NOKOGIRI_NO_FREE")) return ; if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"nokogiri: %s:%d %p start\n", __FILE__, __LINE__, p);
102
- #define NOKOGIRI_DEBUG_END(p) if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"nokogiri: %s:%d %p end\n", __FILE__, __LINE__, p);
110
+ # define NOKOGIRI_DEBUG_START(p) if (getenv("NOKOGIRI_NO_FREE")) return ; if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"nokogiri: %s:%d %p start\n", __FILE__, __LINE__, p);
111
+ # define NOKOGIRI_DEBUG_END(p) if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"nokogiri: %s:%d %p end\n", __FILE__, __LINE__, p);
103
112
 
104
113
  #else
105
114
 
106
- #define NOKOGIRI_DEBUG_START(p)
107
- #define NOKOGIRI_DEBUG_END(p)
115
+ # define NOKOGIRI_DEBUG_START(p)
116
+ # define NOKOGIRI_DEBUG_END(p)
108
117
 
109
118
  #endif
110
119
 
111
120
  #ifndef __builtin_expect
112
- # if defined(__GNUC__)
113
- # define __builtin_expect(expr, c) __builtin_expect((long)(expr), (long)(c))
114
- # endif
121
+ # if defined(__GNUC__)
122
+ # define __builtin_expect(expr, c) __builtin_expect((long)(expr), (long)(c))
123
+ # endif
115
124
  #endif
116
125
 
117
126
  #define XMLNS_PREFIX "xmlns"