nokogiri 1.5.4.rc3-java → 1.5.5-java

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 (39) hide show
  1. data/CHANGELOG.ja.rdoc +35 -18
  2. data/CHANGELOG.rdoc +22 -1
  3. data/README.ja.rdoc +5 -5
  4. data/README.rdoc +9 -9
  5. data/ROADMAP.md +20 -20
  6. data/Rakefile +16 -5
  7. data/Y_U_NO_GEMSPEC.md +3 -3
  8. data/ext/java/nokogiri/HtmlElementDescription.java +1 -1
  9. data/ext/java/nokogiri/HtmlEntityLookup.java +1 -1
  10. data/ext/java/nokogiri/XmlComment.java +14 -5
  11. data/ext/java/nokogiri/XmlElement.java +1 -59
  12. data/ext/java/nokogiri/XmlNode.java +71 -19
  13. data/ext/java/nokogiri/XmlNodeSet.java +1 -1
  14. data/ext/java/nokogiri/XmlReader.java +48 -15
  15. data/ext/java/nokogiri/XmlSyntaxError.java +9 -4
  16. data/ext/java/nokogiri/XmlXpathContext.java +8 -7
  17. data/ext/java/nokogiri/internals/NokogiriHandler.java +7 -1
  18. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +1 -5
  19. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +1 -1
  20. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +1 -1
  21. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +1 -1
  22. data/ext/java/nokogiri/internals/ParserContext.java +65 -104
  23. data/ext/java/nokogiri/internals/XmlDeclHandler.java +1 -1
  24. data/ext/java/nokogiri/internals/XmlDomParser.java +4 -6
  25. data/ext/java/nokogiri/internals/XmlDomParserContext.java +15 -12
  26. data/ext/nokogiri/xml_node.c +2 -2
  27. data/lib/nokogiri/css/parser.rb +75 -79
  28. data/lib/nokogiri/html/document.rb +1 -1
  29. data/lib/nokogiri/nokogiri.jar +0 -0
  30. data/lib/nokogiri/version.rb +1 -1
  31. data/lib/nokogiri/xml/node.rb +1 -1
  32. data/lib/nokogiri/xml/node/save_options.rb +1 -1
  33. data/test/html/test_document.rb +17 -0
  34. data/test/xml/test_document.rb +1 -1
  35. data/test/xml/test_dtd.rb +3 -7
  36. data/test/xml/test_entity_reference.rb +214 -0
  37. data/test/xml/test_node_reparenting.rb +9 -1
  38. data/test/xml/test_xpath.rb +28 -1
  39. metadata +17 -26
@@ -167,28 +167,33 @@ public class XmlNode extends RubyObject {
167
167
  * @param anchorNode
168
168
  */
169
169
  protected static void coalesceTextNodes(ThreadContext context,
170
- IRubyObject anchorNode) {
170
+ IRubyObject anchorNode,
171
+ AdoptScheme scheme) {
171
172
  XmlNode xa = asXmlNode(context, anchorNode);
172
173
 
173
174
  XmlNode xp = asXmlNodeOrNull(context, xa.previous_sibling(context));
174
175
  XmlNode xn = asXmlNodeOrNull(context, xa.next_sibling(context));
175
-
176
+
176
177
  Node p = xp == null ? null : xp.node;
177
178
  Node a = xa.node;
178
179
  Node n = xn == null ? null : xn.node;
179
-
180
+
180
181
  Node parent = a.getParentNode();
181
182
 
182
- if (p != null && p.getNodeType() == Node.TEXT_NODE) {
183
- xa.setContent(p.getNodeValue() + a.getNodeValue());
184
- parent.removeChild(p);
185
- xp.assimilateXmlNode(context, xa);
186
- }
187
- if (n != null && n.getNodeType() == Node.TEXT_NODE) {
183
+ boolean shouldMergeP = scheme == AdoptScheme.NEXT_SIBLING || scheme == AdoptScheme.CHILD || scheme == AdoptScheme.REPLACEMENT;
184
+ boolean shouldMergeN = scheme == AdoptScheme.PREV_SIBLING || scheme == AdoptScheme.REPLACEMENT;
185
+
186
+ // apply the merge right to left
187
+ if (shouldMergeN && n != null && n.getNodeType() == Node.TEXT_NODE) {
188
188
  xa.setContent(a.getNodeValue() + n.getNodeValue());
189
189
  parent.removeChild(n);
190
190
  xn.assimilateXmlNode(context, xa);
191
191
  }
192
+ if (shouldMergeP && p != null && p.getNodeType() == Node.TEXT_NODE) {
193
+ xp.setContent(p.getNodeValue() + a.getNodeValue());
194
+ parent.removeChild(a);
195
+ xa.assimilateXmlNode(context, xp);
196
+ }
192
197
  }
193
198
 
194
199
  /**
@@ -318,7 +323,15 @@ public class XmlNode extends RubyObject {
318
323
  throw getRuntime().newArgumentError("node must have owner document");
319
324
  }
320
325
 
321
- Element element = document.createElementNS(null, rubyStringToString(name));
326
+ Element element = null;
327
+ String node_name = rubyStringToString(name);
328
+ try {
329
+ element = document.createElementNS(null, node_name);
330
+ } catch (org.w3c.dom.DOMException e) {
331
+ // issue#683 NAMESPACE_ERR is thrown from RDF::RDFXML::Writer.new
332
+ // retry without namespace
333
+ element = document.createElement(node_name);
334
+ }
322
335
  setNode(context, element);
323
336
  }
324
337
 
@@ -396,7 +409,10 @@ public class XmlNode extends RubyObject {
396
409
 
397
410
  public boolean isComment() { return false; }
398
411
 
399
- public boolean isElement() { return false; }
412
+ public boolean isElement() {
413
+ if (node instanceof Element) return true; // in case of subclassing
414
+ else return false;
415
+ }
400
416
 
401
417
  public boolean isProcessingInstruction() { return false; }
402
418
 
@@ -430,7 +446,33 @@ public class XmlNode extends RubyObject {
430
446
  }
431
447
 
432
448
  public void relink_namespace(ThreadContext context) {
433
- //this should delegate to subclasses' implementation
449
+ if (node instanceof Element) {
450
+ Element e = (Element) node;
451
+ e.getOwnerDocument().renameNode(e, e.lookupNamespaceURI(e.getPrefix()), e.getNodeName());
452
+
453
+ if (e.hasAttributes()) {
454
+ NamedNodeMap attrs = e.getAttributes();
455
+
456
+ for (int i = 0; i < attrs.getLength(); i++) {
457
+ Attr attr = (Attr) attrs.item(i);
458
+ String nsUri = "";
459
+ String prefix = attr.getPrefix();
460
+ String nodeName = attr.getNodeName();
461
+ if ("xml".equals(prefix)) {
462
+ nsUri = "http://www.w3.org/XML/1998/namespace";
463
+ } else if ("xmlns".equals(prefix) || nodeName.equals("xmlns")) {
464
+ nsUri = "http://www.w3.org/2000/xmlns/";
465
+ } else {
466
+ nsUri = attr.getNamespaceURI();
467
+ }
468
+ e.getOwnerDocument().renameNode(attr, nsUri, nodeName);
469
+ }
470
+ }
471
+
472
+ if (e.hasChildNodes()) {
473
+ ((XmlNodeSet) children(context)).relink_namespace(context);
474
+ }
475
+ }
434
476
  }
435
477
 
436
478
  // Users might extend XmlNode. This method works for such a case.
@@ -519,7 +561,15 @@ public class XmlNode extends RubyObject {
519
561
  IRubyObject prefix,
520
562
  IRubyObject href) {
521
563
  Node namespaceOwner;
522
- if (node.getNodeType() == Node.ELEMENT_NODE) namespaceOwner = node;
564
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
565
+ namespaceOwner = node;
566
+ Element element = (Element) node;
567
+
568
+ final String uri = "http://www.w3.org/2000/xmlns/";
569
+ String qName =
570
+ prefix.isNil() ? "xmlns" : "xmlns:" + rubyStringToString(prefix);
571
+ element.setAttributeNS(uri, qName, rubyStringToString(href));
572
+ }
523
573
  else if (node.getNodeType() == Node.ATTRIBUTE_NODE) namespaceOwner = ((Attr)node).getOwnerElement();
524
574
  else namespaceOwner = node.getParentNode();
525
575
  XmlNamespace ns = XmlNamespace.createFromPrefixAndHref(namespaceOwner, prefix, href);
@@ -758,7 +808,12 @@ public class XmlNode extends RubyObject {
758
808
  String textContent;
759
809
  if (content != null) textContent = rubyStringToString(content);
760
810
  else if (this instanceof XmlDocument) {
761
- textContent = ((Document)this.node).getDocumentElement().getTextContent().trim();
811
+ Node node = ((Document)this.node).getDocumentElement();
812
+ if (node == null) {
813
+ textContent = "";
814
+ } else {
815
+ textContent = ((Document)this.node).getDocumentElement().getTextContent().trim();
816
+ }
762
817
  } else {
763
818
  textContent = this.node.getTextContent();
764
819
  }
@@ -1324,7 +1379,7 @@ public class XmlNode extends RubyObject {
1324
1379
  }
1325
1380
 
1326
1381
  if (otherNode.getNodeType() == Node.TEXT_NODE) {
1327
- coalesceTextNodes(context, other);
1382
+ coalesceTextNodes(context, other, scheme);
1328
1383
  }
1329
1384
 
1330
1385
  relink_namespace(context);
@@ -1374,10 +1429,7 @@ public class XmlNode extends RubyObject {
1374
1429
  otherNode.getParentNode().removeChild(otherNode);
1375
1430
  return;
1376
1431
  }
1377
- if (thisNode.getPreviousSibling() != null &&
1378
- thisNode.getPreviousSibling().getNodeType() == Node.TEXT_NODE &&
1379
- otherNode.getNodeType() == Node.TEXT_NODE) return;
1380
-
1432
+
1381
1433
  parent.insertBefore(otherNode, thisNode);
1382
1434
  }
1383
1435
 
@@ -93,7 +93,7 @@ public class XmlNodeSet extends RubyObject implements NodeList {
93
93
  setNodes(nodeListToRubyArray(getRuntime(), nodeList));
94
94
  }
95
95
 
96
- private void initialize(Ruby ruby, IRubyObject refNode) {
96
+ public void initialize(Ruby ruby, IRubyObject refNode) {
97
97
  if (refNode instanceof XmlNode) {
98
98
  XmlNode n = (XmlNode)refNode;
99
99
  doc = n.document(ruby.getCurrentContext());
@@ -40,6 +40,9 @@ import java.io.IOException;
40
40
  import java.util.ArrayDeque;
41
41
  import java.util.Stack;
42
42
 
43
+ import nokogiri.internals.NokogiriEntityResolver;
44
+ import nokogiri.internals.ParserContext;
45
+ import nokogiri.internals.ParserContext.Options;
43
46
  import nokogiri.internals.ReaderNode;
44
47
  import nokogiri.internals.ReaderNode.ElementNode;
45
48
 
@@ -54,6 +57,7 @@ import org.jruby.anno.JRubyClass;
54
57
  import org.jruby.anno.JRubyMethod;
55
58
  import org.jruby.exceptions.RaiseException;
56
59
  import org.jruby.javasupport.util.RuntimeHelpers;
60
+ import org.jruby.lexer.yacc.SyntaxException;
57
61
  import org.jruby.runtime.ThreadContext;
58
62
  import org.jruby.runtime.builtin.IRubyObject;
59
63
  import org.jruby.util.ByteList;
@@ -97,20 +101,22 @@ public class XmlReader extends RubyObject {
97
101
  public Object clone() throws CloneNotSupportedException {
98
102
  return super.clone();
99
103
  }
100
-
104
+
101
105
  public void init(Ruby runtime) {
102
106
  nodeQueue = new ArrayDeque<ReaderNode>();
103
107
  nodeQueue.add(new ReaderNode.EmptyNode(runtime));
104
108
  }
105
109
 
106
- private void parseRubyString(ThreadContext context, RubyString content){
110
+ private void parseRubyString(ThreadContext context, RubyString content, IRubyObject url, Options options){
107
111
  Ruby ruby = context.getRuntime();
108
112
  try {
109
113
  this.setState(XML_TEXTREADER_MODE_READING);
110
- XMLReader reader = this.createReader(ruby);
114
+ XMLReader reader = this.createReader(ruby, options);
111
115
  ByteList byteList = content.getByteList();
112
116
  ByteArrayInputStream bais = new ByteArrayInputStream(byteList.unsafeBytes(), byteList.begin(), byteList.length());
113
- reader.parse(new InputSource(bais));
117
+ InputSource inputSource = new InputSource(bais);
118
+ ParserContext.setUrl(context, inputSource, url);
119
+ reader.parse(inputSource);
114
120
  this.setState(XML_TEXTREADER_MODE_CLOSED);
115
121
  } catch (SAXParseException spe) {
116
122
  this.setState(XML_TEXTREADER_MODE_ERROR);
@@ -188,16 +194,26 @@ public class XmlReader extends RubyObject {
188
194
  reader.init(runtime);
189
195
  reader.setInstanceVariable("@source", args[0]);
190
196
  reader.setInstanceVariable("@errors", runtime.newArray());
197
+ IRubyObject url = context.nil;
198
+ if (args.length > 1) url = args[1];
191
199
  if (args.length > 2) reader.setInstanceVariable("@encoding", args[2]);
192
200
 
193
201
  RubyString content = RuntimeHelpers.invoke(context, args[0], "read").convertToString();
194
- reader.parseRubyString(context, content);
202
+
203
+ Options options;
204
+ if (args.length > 3) {
205
+ options = new ParserContext.Options((Long)args[3].toJava(Long.class));
206
+ } else {
207
+ // use the default options RECOVER | NONET
208
+ options = new ParserContext.Options(2048 | 1);
209
+ }
210
+ reader.parseRubyString(context, content, url, options);
195
211
  return reader;
196
212
  }
197
213
 
198
214
  @JRubyMethod(meta = true, rest = true)
199
215
  public static IRubyObject from_memory(ThreadContext context, IRubyObject cls, IRubyObject args[]) {
200
- // args[0]: string, args[1]: url, args[2]: encoding, args[3]: options
216
+ // args[0]: string, args[1]: url, args[2]: encoding, args[3]: options
201
217
  Ruby runtime = context.getRuntime();
202
218
  // Not nil allowed!
203
219
  if(args[0].isNil()) throw runtime.newArgumentError("string cannot be nil");
@@ -206,9 +222,18 @@ public class XmlReader extends RubyObject {
206
222
  reader.init(runtime);
207
223
  reader.setInstanceVariable("@source", args[0]);
208
224
  reader.setInstanceVariable("@errors", runtime.newArray());
225
+ IRubyObject url = context.nil;
226
+ if (args.length > 1) url = args[1];
209
227
  if (args.length > 2) reader.setInstanceVariable("@encoding", args[2]);
210
228
 
211
- reader.parseRubyString(context, args[0].convertToString());
229
+ Options options;
230
+ if (args.length > 3) {
231
+ options = new ParserContext.Options((Long)args[3].toJava(Long.class));
232
+ } else {
233
+ // use the default options RECOVER | NONET
234
+ options = new ParserContext.Options(2048 | 1);
235
+ }
236
+ reader.parseRubyString(context, args[0].convertToString(), url, options);
212
237
  return reader;
213
238
  }
214
239
 
@@ -227,13 +252,13 @@ public class XmlReader extends RubyObject {
227
252
  if (current.depth < 0) return null;
228
253
  if (!current.hasChildren) return null;
229
254
  StringBuffer sb = new StringBuffer();
230
- int currentDepth = (Integer)current.depth;
255
+ int currentDepth = current.depth;
231
256
  int inner = 0;
232
257
  for (ReaderNode node : nodeQueue) {
233
- if (((Integer)node.depth) == currentDepth && node.getName().equals(current.getName())) {
258
+ if (node.depth == currentDepth && node.getName().equals(current.getName())) {
234
259
  inner++;
235
260
  }
236
- if (((Integer)node.depth) > currentDepth) {
261
+ if (node.depth > currentDepth) {
237
262
  sb.append(node.getString());
238
263
  }
239
264
  if (inner == 2) break;
@@ -249,11 +274,11 @@ public class XmlReader extends RubyObject {
249
274
  private String getOuterXml(ArrayDeque<ReaderNode> nodeQueue, ReaderNode current) {
250
275
  if (current.depth < 0) return null;
251
276
  StringBuffer sb = new StringBuffer();
252
- int initialDepth = (Integer)current.depth;
277
+ int initialDepth = current.depth;
253
278
  int inner = 0;
254
279
  for (ReaderNode node : nodeQueue) {
255
- if (((Integer)node.depth) >= initialDepth) {
256
- if (((Integer)node.depth) == initialDepth && node.getName().equals(current.getName())) {
280
+ if (node.depth >= initialDepth) {
281
+ if (node.depth == initialDepth && node.getName().equals(current.getName())) {
257
282
  inner++;
258
283
  }
259
284
 
@@ -331,7 +356,7 @@ public class XmlReader extends RubyObject {
331
356
  return nodeQueue.peek().getXmlVersion();
332
357
  }
333
358
 
334
- protected XMLReader createReader(final Ruby ruby) {
359
+ protected XMLReader createReader(final Ruby ruby, Options options) {
335
360
  DefaultHandler2 handler = new DefaultHandler2() {
336
361
 
337
362
  Stack<String> langStack;
@@ -401,6 +426,13 @@ public class XmlReader extends RubyObject {
401
426
  elementStack.push((ReaderNode.ElementNode)readerNode);
402
427
  }
403
428
 
429
+ @Override
430
+ public void skippedEntity(String name) {
431
+ XmlSyntaxError error = XmlSyntaxError.createNokogiriXmlSyntaxError(ruby);
432
+ error.setException(new Exception("Unknown entity " + name));
433
+ throw new RaiseException(error);
434
+ }
435
+
404
436
  @Override
405
437
  public void warning(SAXParseException ex) throws SAXParseException {
406
438
  nodeQueue.add(new ReaderNode.ExceptionNode(ruby, ex));
@@ -412,9 +444,10 @@ public class XmlReader extends RubyObject {
412
444
  reader.setContentHandler(handler);
413
445
  reader.setDTDHandler(handler);
414
446
  reader.setErrorHandler(handler);
447
+ reader.setEntityResolver(new NokogiriEntityResolver(ruby, null, options));
415
448
  reader.setFeature("http://xml.org/sax/features/xmlns-uris", true);
416
449
  reader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
417
- reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
450
+ reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", options.dtdLoad || options.dtdValid);
418
451
  return reader;
419
452
  } catch (SAXException saxe) {
420
453
  throw RaiseException.createNativeRaiseException(ruby, saxe);
@@ -75,23 +75,27 @@ public class XmlSyntaxError extends RubyException {
75
75
  }
76
76
 
77
77
  public static XmlSyntaxError createWarning(Ruby runtime, SAXParseException e) {
78
- XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::SyntaxError"));
78
+ XmlSyntaxError xmlSyntaxError = createNokogiriXmlSyntaxError(runtime);
79
79
  xmlSyntaxError.setException(runtime, e, 1);
80
80
  return xmlSyntaxError;
81
81
  }
82
82
 
83
83
  public static XmlSyntaxError createError(Ruby runtime, SAXParseException e) {
84
- XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::SyntaxError"));
84
+ XmlSyntaxError xmlSyntaxError = createNokogiriXmlSyntaxError(runtime);
85
85
  xmlSyntaxError.setException(runtime, e, 2);
86
86
  return xmlSyntaxError;
87
87
  }
88
88
 
89
89
  public static XmlSyntaxError createFatalError(Ruby runtime, SAXParseException e) {
90
- XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::SyntaxError"));
90
+ XmlSyntaxError xmlSyntaxError = createNokogiriXmlSyntaxError(runtime);
91
91
  xmlSyntaxError.setException(runtime, e, 3);
92
92
  return xmlSyntaxError;
93
93
  }
94
-
94
+
95
+ public static XmlSyntaxError createNokogiriXmlSyntaxError(Ruby runtime) {
96
+ return (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::SyntaxError"));
97
+ }
98
+
95
99
  public void setException(Exception exception) {
96
100
  this.exception = exception;
97
101
  }
@@ -112,6 +116,7 @@ public class XmlSyntaxError extends RubyException {
112
116
  //@Override
113
117
  //"to_s" method was branched in 1.8 and 1.9 since JRuby 1.6.6
114
118
  // to support older version of JRuby, the annotation is commented out
119
+ @Override
115
120
  @JRubyMethod(name = "to_s", compat = CompatVersion.RUBY1_8)
116
121
  public IRubyObject to_s(ThreadContext context) {
117
122
  if (exception != null && exception.getMessage() != null)
@@ -94,16 +94,16 @@ public class XmlXpathContext extends RubyObject {
94
94
  }
95
95
 
96
96
  @JRubyMethod(name = "new", meta = true)
97
- public static IRubyObject rbNew(ThreadContext context, IRubyObject klazz, IRubyObject node) {
97
+ public static IRubyObject rbNew(ThreadContext thread_context, IRubyObject klazz, IRubyObject node) {
98
98
  XmlNode xmlNode = (XmlNode)node;
99
- XmlXpathContext xmlXpathContext = (XmlXpathContext) NokogiriService.XML_XPATHCONTEXT_ALLOCATOR.allocate(context.getRuntime(), (RubyClass)klazz);
99
+ XmlXpathContext xmlXpathContext = (XmlXpathContext) NokogiriService.XML_XPATHCONTEXT_ALLOCATOR.allocate(thread_context.getRuntime(), (RubyClass)klazz);
100
100
  xmlXpathContext.xpath = XPathFactory.newInstance().newXPath();
101
101
  xmlXpathContext.setNode(xmlNode);
102
102
  return xmlXpathContext;
103
103
  }
104
104
 
105
105
  @JRubyMethod
106
- public IRubyObject evaluate(ThreadContext context, IRubyObject expr, IRubyObject handler) {
106
+ public IRubyObject evaluate(ThreadContext thread_context, IRubyObject expr, IRubyObject handler) {
107
107
  String src = (String) expr.toJava(String.class);
108
108
  try {
109
109
  if(!handler.isNil()) {
@@ -116,7 +116,7 @@ public class XmlXpathContext extends RubyObject {
116
116
  xpath.setXPathFunctionResolver(NokogiriXPathFunctionResolver.create(handler));
117
117
  }
118
118
  XPathExpression xpathExpression = xpath.compile(src);
119
- return node_set(context, xpathExpression);
119
+ return node_set(thread_context, xpathExpression);
120
120
  } catch (XPathExpressionException xpee) {
121
121
  xpee = new XPathExpressionException(src);
122
122
  RubyException e = XmlSyntaxError.createXPathSyntaxError(getRuntime(), xpee);
@@ -124,10 +124,10 @@ public class XmlXpathContext extends RubyObject {
124
124
  }
125
125
  }
126
126
 
127
- protected IRubyObject node_set(ThreadContext rbctx, XPathExpression xpathExpression) {
127
+ protected IRubyObject node_set(ThreadContext thread_context, XPathExpression xpathExpression) {
128
128
  XmlNodeSet result = null;
129
129
  try {
130
- result = tryGetNodeSet(xpathExpression);
130
+ result = tryGetNodeSet(thread_context, xpathExpression);
131
131
  return result;
132
132
  } catch (XPathExpressionException xpee) {
133
133
  try {
@@ -139,10 +139,11 @@ public class XmlXpathContext extends RubyObject {
139
139
  }
140
140
  }
141
141
 
142
- private XmlNodeSet tryGetNodeSet(XPathExpression xpathExpression) throws XPathExpressionException {
142
+ private XmlNodeSet tryGetNodeSet(ThreadContext thread_context, XPathExpression xpathExpression) throws XPathExpressionException {
143
143
  NodeList nodeList = (NodeList)xpathExpression.evaluate(context.node, XPathConstants.NODESET);
144
144
  XmlNodeSet xmlNodeSet = (XmlNodeSet) NokogiriService.XML_NODESET_ALLOCATOR.allocate(getRuntime(), getNokogiriClass(getRuntime(), "Nokogiri::XML::NodeSet"));
145
145
  xmlNodeSet.setNodeList(nodeList);
146
+ xmlNodeSet.initialize(thread_context.getRuntime(), context);
146
147
  return xmlNodeSet;
147
148
  }
148
149
 
@@ -92,7 +92,13 @@ public class NokogiriHandler extends DefaultHandler2 implements XmlDeclHandler {
92
92
  String objectName = object.getMetaClass().getName();
93
93
  if (htmlParserName.equals(objectName)) needEmptyAttrCheck = true;
94
94
  }
95
-
95
+
96
+ @Override
97
+ public void skippedEntity(String skippedEntity) {
98
+ call("error", ruby.newString("Entity '" + skippedEntity + "' not defined\n"));
99
+ }
100
+
101
+ @Override
96
102
  public void setDocumentLocator(Locator locator) {
97
103
  this.locator = locator;
98
104
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * (The MIT License)
3
3
  *
4
- * Copyright (c) 2008 - 2011:
4
+ * Copyright (c) 2008 - 2012:
5
5
  *
6
6
  * * {Aaron Patterson}[http://tenderlovemaking.com]
7
7
  * * {Mike Dalessio}[http://mike.daless.io]
@@ -32,7 +32,6 @@
32
32
 
33
33
  package nokogiri.internals;
34
34
 
35
- import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
36
35
  import static nokogiri.internals.NokogiriHelpers.isNamespace;
37
36
 
38
37
  import java.util.ArrayList;
@@ -40,11 +39,8 @@ import java.util.LinkedHashMap;
40
39
  import java.util.List;
41
40
  import java.util.Map;
42
41
 
43
- import nokogiri.NokogiriService;
44
- import nokogiri.XmlDocument;
45
42
  import nokogiri.XmlNamespace;
46
43
 
47
- import org.jruby.Ruby;
48
44
  import org.w3c.dom.Attr;
49
45
  import org.w3c.dom.NamedNodeMap;
50
46
  import org.w3c.dom.Node;