nokogiri 1.10.6-java → 1.11.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -0
  3. data/LICENSE-DEPENDENCIES.md +1015 -947
  4. data/README.md +165 -91
  5. data/ext/java/nokogiri/HtmlDocument.java +34 -46
  6. data/ext/java/nokogiri/HtmlSaxParserContext.java +88 -58
  7. data/ext/java/nokogiri/HtmlSaxPushParser.java +1 -1
  8. data/ext/java/nokogiri/NokogiriService.java +1 -1
  9. data/ext/java/nokogiri/XmlAttr.java +13 -20
  10. data/ext/java/nokogiri/XmlAttributeDecl.java +11 -12
  11. data/ext/java/nokogiri/XmlCdata.java +3 -4
  12. data/ext/java/nokogiri/XmlComment.java +1 -1
  13. data/ext/java/nokogiri/XmlDocument.java +148 -175
  14. data/ext/java/nokogiri/XmlDocumentFragment.java +13 -31
  15. data/ext/java/nokogiri/XmlDtd.java +5 -8
  16. data/ext/java/nokogiri/XmlElement.java +1 -20
  17. data/ext/java/nokogiri/XmlElementDecl.java +23 -28
  18. data/ext/java/nokogiri/XmlEntityDecl.java +23 -27
  19. data/ext/java/nokogiri/XmlEntityReference.java +2 -2
  20. data/ext/java/nokogiri/XmlNamespace.java +72 -89
  21. data/ext/java/nokogiri/XmlNode.java +303 -406
  22. data/ext/java/nokogiri/XmlNodeSet.java +72 -77
  23. data/ext/java/nokogiri/XmlReader.java +12 -13
  24. data/ext/java/nokogiri/XmlRelaxng.java +10 -3
  25. data/ext/java/nokogiri/XmlSaxParserContext.java +15 -10
  26. data/ext/java/nokogiri/XmlSchema.java +87 -27
  27. data/ext/java/nokogiri/XmlSyntaxError.java +2 -6
  28. data/ext/java/nokogiri/XmlText.java +12 -9
  29. data/ext/java/nokogiri/XmlXpathContext.java +55 -25
  30. data/ext/java/nokogiri/XsltStylesheet.java +7 -15
  31. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +52 -46
  32. data/ext/java/nokogiri/internals/NokogiriHandler.java +1 -1
  33. data/ext/java/nokogiri/internals/NokogiriHelpers.java +71 -135
  34. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +90 -58
  35. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +9 -2
  36. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +67 -10
  37. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +4 -2
  38. data/ext/java/nokogiri/internals/ParserContext.java +27 -73
  39. data/ext/java/nokogiri/internals/ReaderNode.java +2 -4
  40. data/ext/java/nokogiri/internals/XmlDomParserContext.java +18 -33
  41. data/ext/nokogiri/depend +476 -357
  42. data/ext/nokogiri/extconf.rb +507 -357
  43. data/ext/nokogiri/html_document.c +79 -78
  44. data/ext/nokogiri/html_sax_parser_context.c +2 -2
  45. data/ext/nokogiri/nokogiri.c +34 -40
  46. data/ext/nokogiri/xml_document.c +18 -4
  47. data/ext/nokogiri/xml_io.c +8 -6
  48. data/ext/nokogiri/xml_node.c +21 -1
  49. data/ext/nokogiri/xml_node_set.c +1 -1
  50. data/ext/nokogiri/xml_reader.c +6 -17
  51. data/ext/nokogiri/xml_relax_ng.c +29 -11
  52. data/ext/nokogiri/xml_sax_parser.c +2 -7
  53. data/ext/nokogiri/xml_sax_parser_context.c +2 -2
  54. data/ext/nokogiri/xml_schema.c +84 -13
  55. data/ext/nokogiri/xml_xpath_context.c +80 -4
  56. data/ext/nokogiri/xslt_stylesheet.c +1 -8
  57. data/lib/nokogiri.rb +22 -22
  58. data/lib/nokogiri/css.rb +1 -0
  59. data/lib/nokogiri/css/node.rb +1 -0
  60. data/lib/nokogiri/css/parser.rb +63 -62
  61. data/lib/nokogiri/css/parser.y +2 -2
  62. data/lib/nokogiri/css/parser_extras.rb +39 -36
  63. data/lib/nokogiri/css/syntax_error.rb +1 -0
  64. data/lib/nokogiri/css/tokenizer.rb +1 -0
  65. data/lib/nokogiri/css/xpath_visitor.rb +73 -43
  66. data/lib/nokogiri/decorators/slop.rb +1 -0
  67. data/lib/nokogiri/html.rb +1 -0
  68. data/lib/nokogiri/html/builder.rb +1 -0
  69. data/lib/nokogiri/html/document.rb +13 -26
  70. data/lib/nokogiri/html/document_fragment.rb +1 -0
  71. data/lib/nokogiri/html/element_description.rb +1 -0
  72. data/lib/nokogiri/html/element_description_defaults.rb +1 -0
  73. data/lib/nokogiri/html/entity_lookup.rb +1 -0
  74. data/lib/nokogiri/html/sax/parser.rb +1 -0
  75. data/lib/nokogiri/html/sax/parser_context.rb +1 -0
  76. data/lib/nokogiri/html/sax/push_parser.rb +1 -0
  77. data/lib/nokogiri/jruby/dependencies.rb +20 -0
  78. data/lib/nokogiri/nokogiri.jar +0 -0
  79. data/lib/nokogiri/syntax_error.rb +1 -0
  80. data/lib/nokogiri/version.rb +3 -109
  81. data/lib/nokogiri/version/constant.rb +5 -0
  82. data/lib/nokogiri/version/info.rb +182 -0
  83. data/lib/nokogiri/xml.rb +1 -0
  84. data/lib/nokogiri/xml/attr.rb +1 -0
  85. data/lib/nokogiri/xml/attribute_decl.rb +1 -0
  86. data/lib/nokogiri/xml/builder.rb +3 -2
  87. data/lib/nokogiri/xml/cdata.rb +1 -0
  88. data/lib/nokogiri/xml/character_data.rb +1 -0
  89. data/lib/nokogiri/xml/document.rb +20 -15
  90. data/lib/nokogiri/xml/document_fragment.rb +5 -6
  91. data/lib/nokogiri/xml/dtd.rb +1 -0
  92. data/lib/nokogiri/xml/element_content.rb +1 -0
  93. data/lib/nokogiri/xml/element_decl.rb +1 -0
  94. data/lib/nokogiri/xml/entity_decl.rb +1 -0
  95. data/lib/nokogiri/xml/entity_reference.rb +1 -0
  96. data/lib/nokogiri/xml/namespace.rb +1 -0
  97. data/lib/nokogiri/xml/node.rb +587 -249
  98. data/lib/nokogiri/xml/node/save_options.rb +1 -0
  99. data/lib/nokogiri/xml/node_set.rb +1 -0
  100. data/lib/nokogiri/xml/notation.rb +1 -0
  101. data/lib/nokogiri/xml/parse_options.rb +10 -3
  102. data/lib/nokogiri/xml/pp.rb +1 -0
  103. data/lib/nokogiri/xml/pp/character_data.rb +1 -0
  104. data/lib/nokogiri/xml/pp/node.rb +1 -0
  105. data/lib/nokogiri/xml/processing_instruction.rb +1 -0
  106. data/lib/nokogiri/xml/reader.rb +7 -3
  107. data/lib/nokogiri/xml/relax_ng.rb +7 -2
  108. data/lib/nokogiri/xml/sax.rb +1 -0
  109. data/lib/nokogiri/xml/sax/document.rb +1 -0
  110. data/lib/nokogiri/xml/sax/parser.rb +1 -0
  111. data/lib/nokogiri/xml/sax/parser_context.rb +1 -0
  112. data/lib/nokogiri/xml/sax/push_parser.rb +1 -0
  113. data/lib/nokogiri/xml/schema.rb +13 -4
  114. data/lib/nokogiri/xml/searchable.rb +25 -16
  115. data/lib/nokogiri/xml/syntax_error.rb +1 -0
  116. data/lib/nokogiri/xml/text.rb +1 -0
  117. data/lib/nokogiri/xml/xpath.rb +1 -0
  118. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -0
  119. data/lib/nokogiri/xml/xpath_context.rb +1 -0
  120. data/lib/nokogiri/xslt.rb +1 -0
  121. data/lib/nokogiri/xslt/stylesheet.rb +1 -0
  122. data/lib/xsd/xmlparser/nokogiri.rb +1 -0
  123. metadata +92 -157
  124. data/ext/java/nokogiri/internals/NokogiriEncodingReaderWrapper.java +0 -107
  125. data/ext/java/nokogiri/internals/UncloseableInputStream.java +0 -102
  126. data/ext/nokogiri/html_document.h +0 -10
  127. data/ext/nokogiri/html_element_description.h +0 -10
  128. data/ext/nokogiri/html_entity_lookup.h +0 -8
  129. data/ext/nokogiri/html_sax_parser_context.h +0 -11
  130. data/ext/nokogiri/html_sax_push_parser.h +0 -9
  131. data/ext/nokogiri/nokogiri.h +0 -121
  132. data/ext/nokogiri/xml_attr.h +0 -9
  133. data/ext/nokogiri/xml_attribute_decl.h +0 -9
  134. data/ext/nokogiri/xml_cdata.h +0 -9
  135. data/ext/nokogiri/xml_comment.h +0 -9
  136. data/ext/nokogiri/xml_document.h +0 -23
  137. data/ext/nokogiri/xml_document_fragment.h +0 -10
  138. data/ext/nokogiri/xml_dtd.h +0 -10
  139. data/ext/nokogiri/xml_element_content.h +0 -10
  140. data/ext/nokogiri/xml_element_decl.h +0 -9
  141. data/ext/nokogiri/xml_encoding_handler.h +0 -8
  142. data/ext/nokogiri/xml_entity_decl.h +0 -10
  143. data/ext/nokogiri/xml_entity_reference.h +0 -9
  144. data/ext/nokogiri/xml_io.h +0 -11
  145. data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
  146. data/ext/nokogiri/xml_namespace.h +0 -14
  147. data/ext/nokogiri/xml_node.h +0 -13
  148. data/ext/nokogiri/xml_node_set.h +0 -12
  149. data/ext/nokogiri/xml_processing_instruction.h +0 -9
  150. data/ext/nokogiri/xml_reader.h +0 -10
  151. data/ext/nokogiri/xml_relax_ng.h +0 -9
  152. data/ext/nokogiri/xml_sax_parser.h +0 -39
  153. data/ext/nokogiri/xml_sax_parser_context.h +0 -10
  154. data/ext/nokogiri/xml_sax_push_parser.h +0 -9
  155. data/ext/nokogiri/xml_schema.h +0 -9
  156. data/ext/nokogiri/xml_syntax_error.h +0 -13
  157. data/ext/nokogiri/xml_text.h +0 -9
  158. data/ext/nokogiri/xml_xpath_context.h +0 -10
  159. data/ext/nokogiri/xslt_stylesheet.h +0 -14
  160. data/patches/libxml2/0001-Revert-Do-not-URI-escape-in-server-side-includes.patch +0 -78
  161. data/patches/libxml2/0002-Remove-script-macro-support.patch +0 -40
  162. data/patches/libxml2/0003-Update-entities-to-remove-handling-of-ssi.patch +0 -44
@@ -39,13 +39,13 @@ import static nokogiri.internals.NokogiriHelpers.nodeListToRubyArray;
39
39
  import java.util.Arrays;
40
40
 
41
41
  import org.jruby.Ruby;
42
+ import org.jruby.RubyArray;
42
43
  import org.jruby.RubyClass;
43
44
  import org.jruby.RubyFixnum;
44
45
  import org.jruby.RubyObject;
45
46
  import org.jruby.RubyRange;
46
47
  import org.jruby.anno.JRubyClass;
47
48
  import org.jruby.anno.JRubyMethod;
48
- import org.jruby.runtime.Block;
49
49
  import org.jruby.runtime.ThreadContext;
50
50
  import org.jruby.runtime.builtin.IRubyObject;
51
51
  import org.w3c.dom.Node;
@@ -60,38 +60,44 @@ import org.w3c.dom.NodeList;
60
60
  @JRubyClass(name="Nokogiri::XML::NodeSet")
61
61
  public class XmlNodeSet extends RubyObject implements NodeList {
62
62
 
63
- private IRubyObject[] nodes;
63
+ IRubyObject[] nodes;
64
64
 
65
- @JRubyMethod(name = "new", meta = true, rest = true)
66
- public static IRubyObject rbNew(ThreadContext context, IRubyObject cls,
67
- IRubyObject[] args, Block block) {
68
- RubyClass klass = (RubyClass) cls;
69
- XmlNodeSet set = (XmlNodeSet) klass.allocate();
70
- set.setNodes(new IRubyObject[0]);
71
- set.callInit(args, block);
72
- return set;
65
+ public XmlNodeSet(Ruby ruby, RubyClass klazz) {
66
+ super(ruby, klazz);
67
+ nodes = IRubyObject.NULL_ARRAY;
73
68
  }
74
69
 
75
- public XmlNodeSet(Ruby ruby, RubyClass klazz) {
70
+ XmlNodeSet(Ruby ruby, RubyClass klazz, IRubyObject[] nodes) {
76
71
  super(ruby, klazz);
72
+ this.nodes = nodes;
77
73
  }
78
74
 
79
- private static XmlNodeSet create(final Ruby runtime) {
80
- return (XmlNodeSet) NokogiriService.XML_NODESET_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"));
75
+ public static XmlNodeSet newEmptyNodeSet(ThreadContext context, XmlNodeSet docOwner) {
76
+ final Ruby runtime = context.runtime;
77
+ XmlNodeSet set = new XmlNodeSet(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"));
78
+ set.initializeFrom(context, docOwner);
79
+ return set;
81
80
  }
82
81
 
83
- public static XmlNodeSet newEmptyNodeSet(ThreadContext context) {
84
- XmlNodeSet set = create(context.getRuntime());
85
- set.nodes = new IRubyObject[0];
82
+ public static XmlNodeSet newEmptyNodeSet(ThreadContext context, XmlNode docOwner) {
83
+ final Ruby runtime = context.runtime;
84
+ XmlNodeSet set = new XmlNodeSet(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"));
85
+ set.initialize(runtime, docOwner);
86
86
  return set;
87
87
  }
88
88
 
89
- public static XmlNodeSet newXmlNodeSet(ThreadContext context, IRubyObject[] nodes) {
90
- XmlNodeSet xmlNodeSet = create(context.runtime);
89
+ public static XmlNodeSet newNodeSet(Ruby runtime, IRubyObject[] nodes) {
90
+ XmlNodeSet xmlNodeSet = new XmlNodeSet(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"));
91
91
  xmlNodeSet.setNodes(nodes);
92
92
  return xmlNodeSet;
93
93
  }
94
94
 
95
+ public static XmlNodeSet newNodeSet(Ruby runtime, IRubyObject[] nodes, XmlNode docOwner) {
96
+ XmlNodeSet set = new XmlNodeSet(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"), nodes);
97
+ set.initialize(runtime, docOwner);
98
+ return set;
99
+ }
100
+
95
101
  /**
96
102
  * Create and return a copy of this object.
97
103
  *
@@ -102,39 +108,33 @@ public class XmlNodeSet extends RubyObject implements NodeList {
102
108
  return super.clone();
103
109
  }
104
110
 
105
- void setNodes(IRubyObject[] array) {
111
+ private void setNodes(IRubyObject[] array) {
106
112
  this.nodes = array;
107
113
 
108
114
  IRubyObject first = array.length > 0 ? array[0] : null;
109
115
  initialize(getRuntime(), first);
110
116
  }
111
117
 
112
- private void setReference(XmlNodeSet reference) {
113
- IRubyObject first = reference.nodes.length > 0 ? reference.nodes[0] : null;
114
- initialize(getRuntime(), first);
115
- }
116
-
117
- public void setNodeList(NodeList nodeList) {
118
- setNodes(nodeListToRubyArray(getRuntime(), nodeList));
118
+ private void initializeFrom(ThreadContext context, XmlNodeSet ref) {
119
+ IRubyObject document = ref.getInstanceVariable("@document");
120
+ if (document != null && !document.isNil()) {
121
+ initialize(context, (XmlDocument) document);
122
+ }
119
123
  }
120
124
 
121
125
  final void initialize(Ruby runtime, IRubyObject refNode) {
122
126
  if (refNode instanceof XmlNode) {
123
- IRubyObject doc = ((XmlNode) refNode).document(runtime);
127
+ XmlDocument doc = ((XmlNode) refNode).document(runtime);
124
128
  setDocumentAndDecorate(runtime.getCurrentContext(), this, doc);
125
129
  }
126
130
  }
127
131
 
128
- public int length() {
129
- return nodes == null ? 0 : nodes.length;
132
+ private void initialize(ThreadContext context, XmlDocument doc) {
133
+ setDocumentAndDecorate(context, this, doc);
130
134
  }
131
135
 
132
- public void relink_namespace(ThreadContext context) {
133
- for (int i = 0; i < nodes.length; i++) {
134
- if (nodes[i] instanceof XmlNode) {
135
- ((XmlNode) nodes[i]).relink_namespace(context);
136
- }
137
- }
136
+ public int length() {
137
+ return nodes == null ? 0 : nodes.length;
138
138
  }
139
139
 
140
140
  @JRubyMethod(name="&")
@@ -142,11 +142,11 @@ public class XmlNodeSet extends RubyObject implements NodeList {
142
142
  IRubyObject[] otherNodes = getNodes(context, nodeSet);
143
143
 
144
144
  if (otherNodes == null || otherNodes.length == 0) {
145
- return newEmptyNodeSet(context);
145
+ return newEmptyNodeSet(context, this);
146
146
  }
147
147
 
148
148
  if (nodes == null || nodes.length == 0) {
149
- return newEmptyNodeSet(context);
149
+ return newEmptyNodeSet(context, this);
150
150
  }
151
151
 
152
152
  IRubyObject[] curr = nodes;
@@ -166,8 +166,8 @@ outer:
166
166
  }
167
167
  }
168
168
 
169
- XmlNodeSet newSet = newXmlNodeSet(context, Arrays.copyOf(result, last));
170
- newSet.setReference(this);
169
+ XmlNodeSet newSet = newNodeSet(context.runtime, Arrays.copyOf(result, last));
170
+ newSet.initializeFrom(context, this);
171
171
  return newSet;
172
172
  }
173
173
 
@@ -210,7 +210,9 @@ outer:
210
210
 
211
211
  @JRubyMethod
212
212
  public IRubyObject dup(ThreadContext context) {
213
- return newXmlNodeSet(context, nodes);
213
+ XmlNodeSet dup = newNodeSet(context.runtime, nodes.clone());
214
+ dup.initializeFrom(context, this);
215
+ return dup;
214
216
  }
215
217
 
216
218
  @JRubyMethod(name = "include?")
@@ -221,12 +223,12 @@ outer:
221
223
  }
222
224
  }
223
225
 
224
- return context.runtime.getFalse();
226
+ return context.fals;
225
227
  }
226
228
 
227
229
  @JRubyMethod(name = {"length", "size"})
228
230
  public IRubyObject length(ThreadContext context) {
229
- return context.getRuntime().newFixnum(nodes.length);
231
+ return context.runtime.newFixnum(nodes.length);
230
232
  }
231
233
 
232
234
  @JRubyMethod(name="-")
@@ -234,11 +236,11 @@ outer:
234
236
  IRubyObject[] otherNodes = getNodes(context, nodeSet);
235
237
 
236
238
  if (otherNodes.length == 0) {
237
- return dup(context);
239
+ return dup(context);
238
240
  }
239
241
 
240
242
  if (nodes.length == 0) {
241
- return newEmptyNodeSet(context);
243
+ return newEmptyNodeSet(context, this);
242
244
  }
243
245
 
244
246
  IRubyObject[] curr = nodes;
@@ -259,8 +261,8 @@ outer:
259
261
  result[last++] = n;
260
262
  }
261
263
 
262
- XmlNodeSet newSet = newXmlNodeSet(context, Arrays.copyOf(result, last));
263
- newSet.setReference(this);
264
+ XmlNodeSet newSet = newNodeSet(context.runtime, Arrays.copyOf(result, last));
265
+ newSet.initializeFrom(context, this);
264
266
  return newSet;
265
267
  }
266
268
 
@@ -294,8 +296,8 @@ outer:
294
296
  result[last++] = n;
295
297
  }
296
298
 
297
- XmlNodeSet newSet = newXmlNodeSet(context, Arrays.copyOf(result, last));
298
- newSet.setReference(this);
299
+ XmlNodeSet newSet = newNodeSet(context.runtime, Arrays.copyOf(result, last));
300
+ newSet.initializeFrom(context, this);
299
301
  return newSet;
300
302
  }
301
303
 
@@ -338,17 +340,7 @@ outer:
338
340
  @JRubyMethod(name={"[]", "slice"})
339
341
  public IRubyObject slice(ThreadContext context, IRubyObject indexOrRange) {
340
342
  if (indexOrRange instanceof RubyFixnum) {
341
- int idx = ((RubyFixnum)indexOrRange).getIntValue();
342
-
343
- if (idx < 0) {
344
- idx += nodes.length;
345
- }
346
-
347
- if (idx >= nodes.length || idx < 0) {
348
- return context.nil;
349
- }
350
-
351
- return nodes[idx];
343
+ return slice(context, ((RubyFixnum) indexOrRange).getIntValue());
352
344
  }
353
345
 
354
346
  int[] begLen = new int[2];
@@ -358,13 +350,25 @@ outer:
358
350
  return subseq(context, min, max - min);
359
351
  }
360
352
 
353
+ IRubyObject slice(ThreadContext context, int idx) {
354
+ if (idx < 0) {
355
+ idx += nodes.length;
356
+ }
357
+
358
+ if (idx >= nodes.length || idx < 0) {
359
+ return context.nil;
360
+ }
361
+
362
+ return nodes[idx];
363
+ }
364
+
361
365
  @JRubyMethod(name={"[]", "slice"})
362
366
  public IRubyObject slice(ThreadContext context, IRubyObject start, IRubyObject length) {
363
367
  int s = ((RubyFixnum) start).getIntValue();
364
368
  int l = ((RubyFixnum) length).getIntValue();
365
369
 
366
370
  if (s < 0) {
367
- s += nodes.length;
371
+ s += nodes.length;
368
372
  }
369
373
 
370
374
  return subseq(context, s, l);
@@ -372,26 +376,24 @@ outer:
372
376
 
373
377
  public IRubyObject subseq(ThreadContext context, int start, int length) {
374
378
  if (start > nodes.length) {
375
- return context.nil;
379
+ return context.nil;
376
380
  }
377
381
 
378
382
  if (start < 0 || length < 0) {
379
- return context.nil;
383
+ return context.nil;
380
384
  }
381
385
 
382
386
  if (start + length > nodes.length) {
383
- length = nodes.length - start;
387
+ length = nodes.length - start;
384
388
  }
385
389
 
386
390
  int to = start + length;
387
391
 
388
- IRubyObject[] newNodes = Arrays.copyOfRange(nodes, start, to);
389
-
390
- return newXmlNodeSet(context, newNodes);
392
+ return newNodeSet(context.runtime, Arrays.copyOfRange(nodes, start, to));
391
393
  }
392
394
 
393
395
  @JRubyMethod(name = {"to_a", "to_ary"})
394
- public IRubyObject to_a(ThreadContext context) {
396
+ public RubyArray to_a(ThreadContext context) {
395
397
  return context.runtime.newArrayNoCopy(nodes);
396
398
  }
397
399
 
@@ -405,13 +407,6 @@ outer:
405
407
  return this;
406
408
  }
407
409
 
408
- private static XmlNodeSet newXmlNodeSet(ThreadContext context, XmlNodeSet reference) {
409
- XmlNodeSet xmlNodeSet = create(context.getRuntime());
410
- xmlNodeSet.setReference(reference);
411
- xmlNodeSet.nodes = new IRubyObject[0];
412
- return xmlNodeSet;
413
- }
414
-
415
410
  private static IRubyObject asXmlNodeOrNamespace(ThreadContext context, IRubyObject possibleNode) {
416
411
  if (possibleNode instanceof XmlNode || possibleNode instanceof XmlNamespace) {
417
412
  return possibleNode;
@@ -419,7 +414,7 @@ outer:
419
414
  throw context.getRuntime().newArgumentError("node must be a Nokogiri::XML::Node or Nokogiri::XML::Namespace");
420
415
  }
421
416
 
422
- static IRubyObject[] getNodes(ThreadContext context, IRubyObject possibleNodeSet) {
417
+ private static IRubyObject[] getNodes(ThreadContext context, IRubyObject possibleNodeSet) {
423
418
  if (possibleNodeSet instanceof XmlNodeSet) {
424
419
  return ((XmlNodeSet) possibleNodeSet).nodes;
425
420
  }
@@ -432,8 +427,8 @@ outer:
432
427
 
433
428
  public Node item(int index) {
434
429
  Object n = nodes[index];
435
- if (n instanceof XmlNode) return ((XmlNode)n).node;
436
- if (n instanceof XmlNamespace) return ((XmlNamespace)n).getNode();
430
+ if (n instanceof XmlNode) return ((XmlNode) n).node;
431
+ if (n instanceof XmlNamespace) return ((XmlNamespace) n).getNode();
437
432
  return null;
438
433
  }
439
434
  }
@@ -41,15 +41,6 @@ import java.util.LinkedList;
41
41
  import java.util.List;
42
42
  import java.util.Stack;
43
43
 
44
- import nokogiri.internals.NokogiriEntityResolver;
45
- import nokogiri.internals.ParserContext;
46
- import nokogiri.internals.ParserContext.Options;
47
- import nokogiri.internals.ReaderNode;
48
- import nokogiri.internals.ReaderNode.ClosingNode;
49
- import nokogiri.internals.ReaderNode.ElementNode;
50
- import nokogiri.internals.ReaderNode.TextNode;
51
- import nokogiri.internals.UncloseableInputStream;
52
-
53
44
  import org.apache.xerces.impl.Constants;
54
45
  import org.apache.xerces.impl.xs.opti.DefaultXMLDocumentHandler;
55
46
  import org.apache.xerces.parsers.StandardParserConfiguration;
@@ -81,6 +72,14 @@ import org.jruby.runtime.builtin.IRubyObject;
81
72
  import org.jruby.util.IOInputStream;
82
73
  import org.xml.sax.InputSource;
83
74
 
75
+ import nokogiri.internals.NokogiriEntityResolver;
76
+ import nokogiri.internals.ParserContext;
77
+ import nokogiri.internals.ParserContext.Options;
78
+ import nokogiri.internals.ReaderNode;
79
+ import nokogiri.internals.ReaderNode.ClosingNode;
80
+ import nokogiri.internals.ReaderNode.ElementNode;
81
+ import nokogiri.internals.ReaderNode.TextNode;
82
+
84
83
  /**
85
84
  * Class for Nokogiri:XML::Reader
86
85
  *
@@ -217,7 +216,7 @@ public class XmlReader extends RubyObject {
217
216
  options = new ParserContext.Options(2048 | 1);
218
217
  }
219
218
 
220
- InputStream in = new UncloseableInputStream(new IOInputStream(args[0]));
219
+ InputStream in = new IOInputStream(args[0]);
221
220
  reader.setInput(context, in, url, options);
222
221
  return reader;
223
222
  }
@@ -245,7 +244,7 @@ public class XmlReader extends RubyObject {
245
244
  options = new ParserContext.Options(2048 | 1);
246
245
  }
247
246
  IRubyObject stringIO = runtime.getClass("StringIO").newInstance(context, args[0], Block.NULL_BLOCK);
248
- InputStream in = new UncloseableInputStream(new IOInputStream(stringIO));
247
+ InputStream in = new IOInputStream(stringIO);
249
248
  reader.setInput(context, in, url, options);
250
249
  return reader;
251
250
  }
@@ -329,7 +328,7 @@ public class XmlReader extends RubyObject {
329
328
  continueParsing = config.parse(false);
330
329
  }
331
330
  catch (XNIException e) {
332
- throw new RaiseException(XmlSyntaxError.createXMLSyntaxError(context.runtime, e)); // Nokogiri::XML::SyntaxError
331
+ throw XmlSyntaxError.createXMLSyntaxError(context.runtime, e).toThrowable(); // Nokogiri::XML::SyntaxError
333
332
  }
334
333
  catch (IOException e) {
335
334
  throw context.runtime.newRuntimeError(e.toString());
@@ -365,7 +364,7 @@ public class XmlReader extends RubyObject {
365
364
  errors.append(error);
366
365
  setInstanceVariable("@errors", errors);
367
366
 
368
- throw ex != null ? ex : new RaiseException((XmlSyntaxError) error);
367
+ throw ex != null ? ex : ((XmlSyntaxError) error).toThrowable();
369
368
  }
370
369
  if ( ex != null ) throw ex;
371
370
  return this;
@@ -56,6 +56,7 @@ import org.jruby.Ruby;
56
56
  import org.jruby.RubyClass;
57
57
  import org.jruby.anno.JRubyClass;
58
58
  import org.jruby.runtime.ThreadContext;
59
+ import org.jruby.runtime.builtin.IRubyObject;
59
60
  import org.w3c.dom.Document;
60
61
  import org.xml.sax.ErrorHandler;
61
62
  import org.xml.sax.SAXException;
@@ -78,11 +79,17 @@ public class XmlRelaxng extends XmlSchema {
78
79
  this.verifier = verifier;
79
80
  }
80
81
 
81
- static XmlSchema createSchemaInstance(ThreadContext context, RubyClass klazz, Source source) {
82
+ static XmlSchema createSchemaInstance(ThreadContext context, RubyClass klazz, Source source, IRubyObject parseOptions) {
82
83
  Ruby runtime = context.getRuntime();
83
84
  XmlRelaxng xmlRelaxng = (XmlRelaxng) NokogiriService.XML_RELAXNG_ALLOCATOR.allocate(runtime, klazz);
85
+
86
+ if (parseOptions == null) {
87
+ parseOptions = defaultParseOptions(context.getRuntime());
88
+ }
89
+
84
90
  xmlRelaxng.setInstanceVariable("@errors", runtime.newEmptyArray());
85
-
91
+ xmlRelaxng.setInstanceVariable("@parse_options", parseOptions);
92
+
86
93
  try {
87
94
  Schema schema = xmlRelaxng.getSchema(source, context);
88
95
  xmlRelaxng.setVerifier(schema.newVerifier());
@@ -128,7 +135,7 @@ public class XmlRelaxng extends XmlSchema {
128
135
  throw context.getRuntime()
129
136
  .newRuntimeError("Could not parse document: "+ex.getMessage());
130
137
  } catch (IOException ex) {
131
- throw context.getRuntime().newIOError(ex.getMessage());
138
+ throw context.getRuntime().newIOError(ex.getClass() + ": " + ex.getMessage());
132
139
  }
133
140
  }
134
141
 
@@ -37,11 +37,6 @@ import static org.jruby.runtime.Helpers.invoke;
37
37
  import java.io.IOException;
38
38
  import java.io.InputStream;
39
39
 
40
- import nokogiri.internals.NokogiriHandler;
41
- import nokogiri.internals.NokogiriHelpers;
42
- import nokogiri.internals.ParserContext;
43
- import nokogiri.internals.XmlSaxParser;
44
-
45
40
  import org.apache.xerces.parsers.AbstractSAXParser;
46
41
  import org.jruby.Ruby;
47
42
  import org.jruby.RubyClass;
@@ -61,6 +56,11 @@ import org.xml.sax.SAXNotRecognizedException;
61
56
  import org.xml.sax.SAXNotSupportedException;
62
57
  import org.xml.sax.SAXParseException;
63
58
 
59
+ import nokogiri.internals.NokogiriHandler;
60
+ import nokogiri.internals.NokogiriHelpers;
61
+ import nokogiri.internals.ParserContext;
62
+ import nokogiri.internals.XmlSaxParser;
63
+
64
64
  /**
65
65
  * Base class for the SAX parsers.
66
66
  *
@@ -94,7 +94,10 @@ public class XmlSaxParserContext extends ParserContext {
94
94
  parser = createParser();
95
95
  }
96
96
  catch (SAXException se) {
97
- throw RaiseException.createNativeRaiseException(runtime, se);
97
+ // Unexpected failure in XML subsystem
98
+ RaiseException ex = runtime.newRuntimeError(se.toString());
99
+ ex.initCause(se);
100
+ throw ex;
98
101
  }
99
102
  }
100
103
 
@@ -126,7 +129,7 @@ public class XmlSaxParserContext extends ParserContext {
126
129
  final Ruby runtime = context.runtime;
127
130
  XmlSaxParserContext ctx = newInstance(runtime, (RubyClass) klazz);
128
131
  ctx.initialize(runtime);
129
- ctx.setInputSource(context, data, runtime.getNil());
132
+ ctx.setStringInputSource(context, data, runtime.getNil());
130
133
  return ctx;
131
134
  }
132
135
 
@@ -160,7 +163,7 @@ public class XmlSaxParserContext extends ParserContext {
160
163
  final Ruby runtime = context.runtime;
161
164
  XmlSaxParserContext ctx = newInstance(runtime, (RubyClass) klazz);
162
165
  ctx.initialize(runtime);
163
- ctx.setInputSource(context, data, runtime.getNil());
166
+ ctx.setIOInputSource(context, data, runtime.getNil());
164
167
  return ctx;
165
168
  }
166
169
 
@@ -208,7 +211,8 @@ public class XmlSaxParserContext extends ParserContext {
208
211
  parser.setFeature(FEATURE_CONTINUE_AFTER_FATAL_ERROR, true);
209
212
  }
210
213
  catch (Exception e) {
211
- throw RaiseException.createNativeRaiseException(runtime, e);
214
+ // Unexpected failure in XML subsystem
215
+ throw runtime.newRuntimeError(e.getMessage());
212
216
  }
213
217
  }
214
218
  }
@@ -261,7 +265,8 @@ public class XmlSaxParserContext extends ParserContext {
261
265
  }
262
266
  }
263
267
  catch (SAXException ex) {
264
- throw RaiseException.createNativeRaiseException(runtime, ex);
268
+ // Unexpected failure in XML subsystem
269
+ throw runtime.newRuntimeError(ex.getMessage());
265
270
  }
266
271
  catch (IOException ex) {
267
272
  throw runtime.newIOErrorFromException(ex);