nokogiri 1.12.3-java → 1.13.1-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 (107) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +5 -0
  3. data/README.md +9 -7
  4. data/bin/nokogiri +63 -50
  5. data/dependencies.yml +5 -6
  6. data/ext/java/nokogiri/Html4SaxPushParser.java +14 -19
  7. data/ext/java/nokogiri/XmlDocumentFragment.java +4 -15
  8. data/ext/java/nokogiri/XmlNamespace.java +0 -8
  9. data/ext/java/nokogiri/XmlNode.java +32 -16
  10. data/ext/java/nokogiri/XmlNodeSet.java +0 -4
  11. data/ext/java/nokogiri/XmlReader.java +12 -0
  12. data/ext/java/nokogiri/XmlSaxParserContext.java +31 -93
  13. data/ext/java/nokogiri/XmlSaxPushParser.java +17 -25
  14. data/ext/java/nokogiri/XmlSchema.java +1 -1
  15. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +1 -1
  16. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +29 -8
  17. data/ext/java/nokogiri/internals/NokogiriHandler.java +6 -24
  18. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +9 -8
  19. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +10 -9
  20. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +7 -6
  21. data/ext/java/nokogiri/internals/SaveContextVisitor.java +2 -0
  22. data/ext/java/nokogiri/internals/XmlDomParserContext.java +16 -25
  23. data/ext/nokogiri/extconf.rb +47 -35
  24. data/ext/nokogiri/xml_document.c +35 -35
  25. data/ext/nokogiri/xml_document_fragment.c +0 -2
  26. data/ext/nokogiri/xml_dtd.c +2 -2
  27. data/ext/nokogiri/xml_encoding_handler.c +25 -11
  28. data/ext/nokogiri/xml_node.c +645 -333
  29. data/ext/nokogiri/xml_reader.c +37 -11
  30. data/ext/nokogiri/xml_xpath_context.c +72 -49
  31. data/ext/nokogiri/xslt_stylesheet.c +107 -9
  32. data/lib/nokogiri/class_resolver.rb +67 -0
  33. data/lib/nokogiri/css/node.rb +9 -8
  34. data/lib/nokogiri/css/parser.rb +360 -341
  35. data/lib/nokogiri/css/parser.y +249 -244
  36. data/lib/nokogiri/css/parser_extras.rb +20 -20
  37. data/lib/nokogiri/css/syntax_error.rb +1 -0
  38. data/lib/nokogiri/css/tokenizer.rb +4 -3
  39. data/lib/nokogiri/css/tokenizer.rex +3 -2
  40. data/lib/nokogiri/css/xpath_visitor.rb +179 -82
  41. data/lib/nokogiri/css.rb +38 -6
  42. data/lib/nokogiri/decorators/slop.rb +8 -7
  43. data/lib/nokogiri/extension.rb +1 -1
  44. data/lib/nokogiri/gumbo.rb +1 -0
  45. data/lib/nokogiri/html.rb +16 -10
  46. data/lib/nokogiri/html4/builder.rb +1 -0
  47. data/lib/nokogiri/html4/document.rb +84 -75
  48. data/lib/nokogiri/html4/document_fragment.rb +11 -7
  49. data/lib/nokogiri/html4/element_description.rb +1 -0
  50. data/lib/nokogiri/html4/element_description_defaults.rb +426 -520
  51. data/lib/nokogiri/html4/entity_lookup.rb +2 -1
  52. data/lib/nokogiri/html4/sax/parser.rb +2 -1
  53. data/lib/nokogiri/html4/sax/parser_context.rb +1 -0
  54. data/lib/nokogiri/html4/sax/push_parser.rb +7 -7
  55. data/lib/nokogiri/html4.rb +11 -5
  56. data/lib/nokogiri/html5/document.rb +24 -10
  57. data/lib/nokogiri/html5/document_fragment.rb +5 -2
  58. data/lib/nokogiri/html5/node.rb +6 -3
  59. data/lib/nokogiri/html5.rb +68 -64
  60. data/lib/nokogiri/jruby/dependencies.rb +10 -9
  61. data/lib/nokogiri/nokogiri.jar +0 -0
  62. data/lib/nokogiri/syntax_error.rb +1 -0
  63. data/lib/nokogiri/version/constant.rb +2 -1
  64. data/lib/nokogiri/version/info.rb +19 -13
  65. data/lib/nokogiri/version.rb +1 -0
  66. data/lib/nokogiri/xml/attr.rb +5 -3
  67. data/lib/nokogiri/xml/attribute_decl.rb +2 -1
  68. data/lib/nokogiri/xml/builder.rb +69 -31
  69. data/lib/nokogiri/xml/cdata.rb +2 -1
  70. data/lib/nokogiri/xml/character_data.rb +1 -0
  71. data/lib/nokogiri/xml/document.rb +178 -96
  72. data/lib/nokogiri/xml/document_fragment.rb +41 -38
  73. data/lib/nokogiri/xml/dtd.rb +3 -2
  74. data/lib/nokogiri/xml/element_content.rb +1 -0
  75. data/lib/nokogiri/xml/element_decl.rb +2 -1
  76. data/lib/nokogiri/xml/entity_decl.rb +3 -2
  77. data/lib/nokogiri/xml/entity_reference.rb +1 -0
  78. data/lib/nokogiri/xml/namespace.rb +2 -0
  79. data/lib/nokogiri/xml/node/save_options.rb +7 -4
  80. data/lib/nokogiri/xml/node.rb +512 -348
  81. data/lib/nokogiri/xml/node_set.rb +46 -54
  82. data/lib/nokogiri/xml/notation.rb +12 -0
  83. data/lib/nokogiri/xml/parse_options.rb +11 -7
  84. data/lib/nokogiri/xml/pp/character_data.rb +8 -6
  85. data/lib/nokogiri/xml/pp/node.rb +24 -26
  86. data/lib/nokogiri/xml/pp.rb +1 -0
  87. data/lib/nokogiri/xml/processing_instruction.rb +2 -1
  88. data/lib/nokogiri/xml/reader.rb +17 -19
  89. data/lib/nokogiri/xml/relax_ng.rb +1 -0
  90. data/lib/nokogiri/xml/sax/document.rb +20 -19
  91. data/lib/nokogiri/xml/sax/parser.rb +36 -34
  92. data/lib/nokogiri/xml/sax/parser_context.rb +7 -3
  93. data/lib/nokogiri/xml/sax/push_parser.rb +5 -5
  94. data/lib/nokogiri/xml/sax.rb +1 -0
  95. data/lib/nokogiri/xml/schema.rb +7 -6
  96. data/lib/nokogiri/xml/searchable.rb +93 -62
  97. data/lib/nokogiri/xml/syntax_error.rb +4 -4
  98. data/lib/nokogiri/xml/text.rb +1 -0
  99. data/lib/nokogiri/xml/xpath/syntax_error.rb +2 -1
  100. data/lib/nokogiri/xml/xpath.rb +12 -0
  101. data/lib/nokogiri/xml/xpath_context.rb +2 -3
  102. data/lib/nokogiri/xml.rb +3 -3
  103. data/lib/nokogiri/xslt/stylesheet.rb +1 -0
  104. data/lib/nokogiri/xslt.rb +21 -13
  105. data/lib/nokogiri.rb +19 -16
  106. data/lib/xsd/xmlparser/nokogiri.rb +25 -24
  107. metadata +102 -30
@@ -1,33 +1,23 @@
1
1
  package nokogiri;
2
2
 
3
- import static org.jruby.runtime.Helpers.invoke;
4
-
5
- import java.io.IOException;
6
- import java.io.InputStream;
7
-
3
+ import nokogiri.internals.*;
8
4
  import org.apache.xerces.parsers.AbstractSAXParser;
9
5
  import org.jruby.Ruby;
10
6
  import org.jruby.RubyClass;
11
7
  import org.jruby.RubyFixnum;
12
- import org.jruby.RubyModule;
13
- import org.jruby.RubyObjectAdapter;
14
8
  import org.jruby.anno.JRubyClass;
15
9
  import org.jruby.anno.JRubyMethod;
16
10
  import org.jruby.exceptions.RaiseException;
17
- import org.jruby.javasupport.JavaEmbedUtils;
11
+ import org.jruby.runtime.Helpers;
18
12
  import org.jruby.runtime.ThreadContext;
19
13
  import org.jruby.runtime.builtin.IRubyObject;
20
- import org.xml.sax.ContentHandler;
21
- import org.xml.sax.ErrorHandler;
22
14
  import org.xml.sax.SAXException;
23
- import org.xml.sax.SAXNotRecognizedException;
24
- import org.xml.sax.SAXNotSupportedException;
25
15
  import org.xml.sax.SAXParseException;
26
16
 
27
- import nokogiri.internals.NokogiriHandler;
28
- import nokogiri.internals.NokogiriHelpers;
29
- import nokogiri.internals.ParserContext;
30
- import nokogiri.internals.XmlSaxParser;
17
+ import java.io.IOException;
18
+ import java.io.InputStream;
19
+
20
+ import static org.jruby.runtime.Helpers.invoke;
31
21
 
32
22
  /**
33
23
  * Base class for the SAX parsers.
@@ -51,6 +41,7 @@ public class XmlSaxParserContext extends ParserContext
51
41
  protected AbstractSAXParser parser;
52
42
 
53
43
  protected NokogiriHandler handler;
44
+ protected NokogiriErrorHandler errorHandler;
54
45
  private boolean replaceEntities = true;
55
46
  private boolean recovery = false;
56
47
 
@@ -168,31 +159,12 @@ public class XmlSaxParserContext extends ParserContext
168
159
  return (XmlSaxParserContext) NokogiriService.XML_SAXPARSER_CONTEXT_ALLOCATOR.allocate(runtime, klazz);
169
160
  }
170
161
 
171
- /**
172
- * Set a property of the underlying parser.
173
- */
174
- protected void
175
- setProperty(String key, Object val)
176
- throws SAXNotRecognizedException, SAXNotSupportedException
177
- {
178
- parser.setProperty(key, val);
179
- }
180
-
181
- protected void
182
- setContentHandler(ContentHandler handler)
183
- {
184
- parser.setContentHandler(handler);
185
- }
186
-
187
- protected void
188
- setErrorHandler(ErrorHandler handler)
189
- {
190
- parser.setErrorHandler(handler);
191
- }
192
-
193
162
  public final NokogiriHandler
194
163
  getNokogiriHandler() { return handler; }
195
164
 
165
+ public final NokogiriErrorHandler
166
+ getNokogiriErrorHandler() { return errorHandler; }
167
+
196
168
  /**
197
169
  * Perform any initialization prior to parsing with the handler
198
170
  * <code>handlerRuby</code>. Convenience hook for subclasses.
@@ -223,6 +195,17 @@ public class XmlSaxParserContext extends ParserContext
223
195
  parser.parse(getInputSource());
224
196
  }
225
197
 
198
+ protected static Options
199
+ defaultParseOptions(ThreadContext context)
200
+ {
201
+ return new ParserContext.Options(
202
+ RubyFixnum.fix2long(Helpers.invoke(context,
203
+ ((RubyClass)context.getRuntime().getClassFromPath("Nokogiri::XML::ParseOptions"))
204
+ .getConstant("DEFAULT_XML"),
205
+ "to_i"))
206
+ );
207
+ }
208
+
226
209
  @JRubyMethod
227
210
  public IRubyObject
228
211
  parse_with(ThreadContext context, IRubyObject handlerRuby)
@@ -233,14 +216,19 @@ public class XmlSaxParserContext extends ParserContext
233
216
  throw runtime.newArgumentError("argument must respond_to document");
234
217
  }
235
218
 
236
- NokogiriHandler handler = this.handler = new NokogiriHandler(runtime, handlerRuby);
237
- preParse(runtime, handlerRuby, handler);
219
+ /* TODO: how should we pass in parse options? */
220
+ ParserContext.Options options = defaultParseOptions(context);
221
+
222
+ errorHandler = new NokogiriStrictErrorHandler(runtime, options.noError, options.noWarning);
223
+ handler = new NokogiriHandler(runtime, handlerRuby, errorHandler);
238
224
 
239
- setContentHandler(handler);
240
- setErrorHandler(handler);
225
+ preParse(runtime, handlerRuby, handler);
226
+ parser.setContentHandler(handler);
227
+ parser.setErrorHandler(handler);
228
+ parser.setEntityResolver(new NokogiriEntityResolver(runtime, errorHandler, options));
241
229
 
242
230
  try {
243
- setProperty("http://xml.org/sax/properties/lexical-handler", handler);
231
+ parser.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
244
232
  } catch (Exception ex) {
245
233
  throw runtime.newRuntimeError("Problem while creating XML SAX Parser: " + ex.toString());
246
234
  }
@@ -270,8 +258,6 @@ public class XmlSaxParserContext extends ParserContext
270
258
 
271
259
  postParse(runtime, handlerRuby, handler);
272
260
 
273
- //maybeTrimLeadingAndTrailingWhitespace(context, handlerRuby);
274
-
275
261
  return runtime.getNil();
276
262
  }
277
263
 
@@ -319,53 +305,6 @@ public class XmlSaxParserContext extends ParserContext
319
305
  return context.runtime.newBoolean(recovery);
320
306
  }
321
307
 
322
- /**
323
- * If the handler's document is a FragmentHandler, attempt to trim
324
- * leading and trailing whitespace.
325
- *
326
- * This is a bit hackish and depends heavily on the internals of
327
- * FragmentHandler.
328
- */
329
- protected void
330
- maybeTrimLeadingAndTrailingWhitespace(ThreadContext context, IRubyObject parser)
331
- {
332
- RubyObjectAdapter adapter = JavaEmbedUtils.newObjectAdapter();
333
- RubyModule mod = context.getRuntime().getClassFromPath("Nokogiri::XML::FragmentHandler");
334
-
335
- IRubyObject handler = adapter.getInstanceVariable(parser, "@document");
336
- if (handler == null || handler.isNil() || !adapter.isKindOf(handler, mod)) {
337
- return;
338
- }
339
- IRubyObject stack = adapter.getInstanceVariable(handler, "@stack");
340
- if (stack == null || stack.isNil()) {
341
- return;
342
- }
343
- // doc is finally a DocumentFragment whose nodes we can check
344
- IRubyObject doc = adapter.callMethod(stack, "first");
345
- if (doc == null || doc.isNil()) {
346
- return;
347
- }
348
-
349
- IRubyObject children;
350
-
351
- for (;;) {
352
- children = adapter.callMethod(doc, "children");
353
- IRubyObject first = adapter.callMethod(children, "first");
354
- if (NokogiriHelpers.isBlank(first)) { adapter.callMethod(first, "unlink"); }
355
- else { break; }
356
- }
357
-
358
- for (;;) {
359
- children = adapter.callMethod(doc, "children");
360
- IRubyObject last = adapter.callMethod(children, "last");
361
- if (NokogiriHelpers.isBlank(last)) { adapter.callMethod(last, "unlink"); }
362
- else { break; }
363
- }
364
-
365
- // While we have a document, normalize it.
366
- ((XmlNode) doc).normalize();
367
- }
368
-
369
308
  @JRubyMethod(name = "column")
370
309
  public IRubyObject
371
310
  column(ThreadContext context)
@@ -383,5 +322,4 @@ public class XmlSaxParserContext extends ParserContext
383
322
  if (number == null) { return context.getRuntime().getNil(); }
384
323
  return RubyFixnum.newFixnum(context.getRuntime(), number.longValue());
385
324
  }
386
-
387
325
  }
@@ -1,20 +1,9 @@
1
1
  package nokogiri;
2
2
 
3
- import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
4
- import static org.jruby.runtime.Helpers.invoke;
5
-
6
- import java.io.ByteArrayInputStream;
7
- import java.io.IOException;
8
- import java.io.InputStream;
9
- import java.util.concurrent.ExecutionException;
10
- import java.util.concurrent.ExecutorService;
11
- import java.util.concurrent.Executors;
12
- import java.util.concurrent.Future;
13
- import java.util.concurrent.FutureTask;
14
- import java.util.concurrent.ThreadFactory;
15
-
3
+ import nokogiri.internals.*;
16
4
  import org.jruby.Ruby;
17
5
  import org.jruby.RubyClass;
6
+ import org.jruby.RubyException;
18
7
  import org.jruby.RubyObject;
19
8
  import org.jruby.anno.JRubyClass;
20
9
  import org.jruby.anno.JRubyMethod;
@@ -22,11 +11,14 @@ import org.jruby.exceptions.RaiseException;
22
11
  import org.jruby.runtime.ThreadContext;
23
12
  import org.jruby.runtime.builtin.IRubyObject;
24
13
 
25
- import nokogiri.internals.ClosedStreamException;
26
- import nokogiri.internals.NokogiriBlockingQueueInputStream;
27
- import nokogiri.internals.NokogiriHandler;
28
- import nokogiri.internals.NokogiriHelpers;
29
- import nokogiri.internals.ParserContext;
14
+ import java.io.ByteArrayInputStream;
15
+ import java.io.IOException;
16
+ import java.io.InputStream;
17
+ import java.util.List;
18
+ import java.util.concurrent.*;
19
+
20
+ import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
21
+ import static org.jruby.runtime.Helpers.invoke;
30
22
 
31
23
  /**
32
24
  * Class for Nokogiri::XML::SAX::PushParser
@@ -159,7 +151,8 @@ public class XmlSaxPushParser extends RubyObject
159
151
 
160
152
  if (!options.recover && parserTask.getErrorCount() > errorCount0) {
161
153
  terminateTask(context.runtime);
162
- throw ex = parserTask.getLastError();
154
+ ex = parserTask.getLastError().toThrowable();
155
+ throw ex;
163
156
  }
164
157
 
165
158
  return this;
@@ -278,16 +271,15 @@ public class XmlSaxPushParser extends RubyObject
278
271
  getErrorCount()
279
272
  {
280
273
  // check for null because thread may not have started yet
281
- if (parser.getNokogiriHandler() == null) { return 0; }
282
- return parser.getNokogiriHandler().getErrorCount();
274
+ if (parser.getNokogiriErrorHandler() == null) { return 0; }
275
+ return parser.getNokogiriErrorHandler().getErrors().size();
283
276
  }
284
277
 
285
- synchronized final RaiseException
278
+ synchronized final RubyException
286
279
  getLastError()
287
280
  {
288
- return parser.getNokogiriHandler().getLastError();
281
+ List<RubyException> errors = parser.getNokogiriErrorHandler().getErrors();
282
+ return errors.get(errors.size() - 1);
289
283
  }
290
-
291
284
  }
292
-
293
285
  }
@@ -276,7 +276,7 @@ public class XmlSchema extends RubyObject
276
276
  String systemId,
277
277
  String baseURI)
278
278
  {
279
- if (noNet && (systemId.startsWith("http://") || systemId.startsWith("ftp://"))) {
279
+ if (noNet && systemId != null && (systemId.startsWith("http://") || systemId.startsWith("ftp://"))) {
280
280
  if (systemId.startsWith(XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
281
281
  return null; // use default resolver
282
282
  }
@@ -85,7 +85,7 @@ public class NokogiriEntityResolver implements EntityResolver2
85
85
  private void
86
86
  addError(String errorMessage)
87
87
  {
88
- if (handler != null) { handler.errors.add(new Exception(errorMessage)); }
88
+ if (handler != null) { handler.addError(new Exception(errorMessage)); }
89
89
  }
90
90
 
91
91
  /**
@@ -1,11 +1,15 @@
1
1
  package nokogiri.internals;
2
2
 
3
- import java.util.ArrayList;
4
- import java.util.List;
5
-
3
+ import nokogiri.XmlSyntaxError;
6
4
  import org.apache.xerces.xni.parser.XMLErrorHandler;
5
+ import org.jruby.Ruby;
6
+ import org.jruby.RubyException;
7
+ import org.jruby.exceptions.RaiseException;
7
8
  import org.xml.sax.ErrorHandler;
8
9
 
10
+ import java.util.ArrayList;
11
+ import java.util.List;
12
+
9
13
  /**
10
14
  * Super class of error handlers.
11
15
  *
@@ -17,23 +21,40 @@ import org.xml.sax.ErrorHandler;
17
21
  */
18
22
  public abstract class NokogiriErrorHandler implements ErrorHandler, XMLErrorHandler
19
23
  {
20
- protected final List<Exception> errors;
24
+ private final Ruby runtime;
25
+ protected final List<RubyException> errors;
21
26
  protected boolean noerror;
22
27
  protected boolean nowarning;
23
28
 
24
29
  public
25
- NokogiriErrorHandler(boolean noerror, boolean nowarning)
30
+ NokogiriErrorHandler(Ruby runtime, boolean noerror, boolean nowarning)
26
31
  {
27
- this.errors = new ArrayList<Exception>(4);
32
+ this.runtime = runtime;
33
+ this.errors = new ArrayList<RubyException>(4);
28
34
  this.noerror = noerror;
29
35
  this.nowarning = nowarning;
30
36
  }
31
37
 
32
- List<Exception>
38
+ public List<RubyException>
33
39
  getErrors() { return errors; }
34
40
 
35
41
  public void
36
- addError(Exception ex) { errors.add(ex); }
42
+ addError(Exception ex)
43
+ {
44
+ addError(XmlSyntaxError.createXMLSyntaxError(runtime, ex));
45
+ }
46
+
47
+ public void
48
+ addError(RubyException ex)
49
+ {
50
+ errors.add(ex);
51
+ }
52
+
53
+ public void
54
+ addError(RaiseException ex)
55
+ {
56
+ addError(ex.getException());
57
+ }
37
58
 
38
59
  protected boolean
39
60
  usesNekoHtml(String domain)
@@ -38,25 +38,19 @@ public class NokogiriHandler extends DefaultHandler2 implements XmlDeclHandler
38
38
  private final Ruby runtime;
39
39
  private final RubyClass attrClass;
40
40
  private final IRubyObject object;
41
-
42
- /**
43
- * Stores parse errors with the most-recent error last.
44
- *
45
- * TODO: should these be stored in the document 'errors' array?
46
- * Currently only string messages are stored there.
47
- */
48
- private final LinkedList<RaiseException> errors = new LinkedList<RaiseException>();
41
+ private NokogiriErrorHandler errorHandler;
49
42
 
50
43
  private Locator locator;
51
44
  private boolean needEmptyAttrCheck;
52
45
 
53
46
  public
54
- NokogiriHandler(Ruby runtime, IRubyObject object)
47
+ NokogiriHandler(Ruby runtime, IRubyObject object, NokogiriErrorHandler errorHandler)
55
48
  {
56
49
  assert object != null;
57
50
  this.runtime = runtime;
58
51
  this.attrClass = (RubyClass) runtime.getClassFromPath("Nokogiri::XML::SAX::Parser::Attribute");
59
52
  this.object = object;
53
+ this.errorHandler = errorHandler;
60
54
  charactersBuilder = new StringBuilder();
61
55
  String objectName = object.getMetaClass().getName();
62
56
  if ("Nokogiri::HTML4::SAX::Parser".equals(objectName)) { needEmptyAttrCheck = true; }
@@ -253,9 +247,9 @@ public class NokogiriHandler extends DefaultHandler2 implements XmlDeclHandler
253
247
  try {
254
248
  final String msg = ex.getMessage();
255
249
  call("error", runtime.newString(msg == null ? "" : msg));
256
- addError(XmlSyntaxError.createError(runtime, ex).toThrowable());
250
+ errorHandler.addError(ex);
257
251
  } catch (RaiseException e) {
258
- addError(e);
252
+ errorHandler.addError(e);
259
253
  throw e;
260
254
  }
261
255
  }
@@ -282,22 +276,10 @@ public class NokogiriHandler extends DefaultHandler2 implements XmlDeclHandler
282
276
  call("warning", runtime.newString(msg == null ? "" : msg));
283
277
  }
284
278
 
285
- protected synchronized void
286
- addError(RaiseException e)
287
- {
288
- errors.add(e);
289
- }
290
-
291
279
  public synchronized int
292
280
  getErrorCount()
293
281
  {
294
- return errors.size();
295
- }
296
-
297
- public synchronized RaiseException
298
- getLastError()
299
- {
300
- return errors.getLast();
282
+ return errorHandler.getErrors().size();
301
283
  }
302
284
 
303
285
  private void
@@ -1,6 +1,7 @@
1
1
  package nokogiri.internals;
2
2
 
3
3
  import org.apache.xerces.xni.parser.XMLParseException;
4
+ import org.jruby.Ruby;
4
5
  import org.xml.sax.SAXException;
5
6
  import org.xml.sax.SAXParseException;
6
7
 
@@ -13,21 +14,21 @@ import org.xml.sax.SAXParseException;
13
14
  public class NokogiriNonStrictErrorHandler extends NokogiriErrorHandler
14
15
  {
15
16
  public
16
- NokogiriNonStrictErrorHandler(boolean noerror, boolean nowarning)
17
+ NokogiriNonStrictErrorHandler(Ruby runtime, boolean noerror, boolean nowarning)
17
18
  {
18
- super(noerror, nowarning);
19
+ super(runtime, noerror, nowarning);
19
20
  }
20
21
 
21
22
  public void
22
23
  warning(SAXParseException ex) throws SAXException
23
24
  {
24
- errors.add(ex);
25
+ addError(ex);
25
26
  }
26
27
 
27
28
  public void
28
29
  error(SAXParseException ex) throws SAXException
29
30
  {
30
- errors.add(ex);
31
+ addError(ex);
31
32
  }
32
33
 
33
34
  public void
@@ -38,7 +39,7 @@ public class NokogiriNonStrictErrorHandler extends NokogiriErrorHandler
38
39
  // found in the prolog, instead it will keep calling this method and we'll
39
40
  // keep inserting the error in the document errors array until we run
40
41
  // out of memory
41
- errors.add(ex);
42
+ addError(ex);
42
43
  String message = ex.getMessage();
43
44
 
44
45
  // The problem with Xerces is that some errors will cause the
@@ -53,19 +54,19 @@ public class NokogiriNonStrictErrorHandler extends NokogiriErrorHandler
53
54
  public void
54
55
  error(String domain, String key, XMLParseException e)
55
56
  {
56
- errors.add(e);
57
+ addError(e);
57
58
  }
58
59
 
59
60
  public void
60
61
  fatalError(String domain, String key, XMLParseException e)
61
62
  {
62
- errors.add(e);
63
+ addError(e);
63
64
  }
64
65
 
65
66
  public void
66
67
  warning(String domain, String key, XMLParseException e)
67
68
  {
68
- errors.add(e);
69
+ addError(e);
69
70
  }
70
71
 
71
72
  /*
@@ -1,6 +1,7 @@
1
1
  package nokogiri.internals;
2
2
 
3
3
  import org.apache.xerces.xni.parser.XMLParseException;
4
+ import org.jruby.Ruby;
4
5
  import org.xml.sax.SAXException;
5
6
  import org.xml.sax.SAXParseException;
6
7
 
@@ -20,15 +21,15 @@ public class NokogiriNonStrictErrorHandler4NekoHtml extends NokogiriErrorHandler
20
21
  {
21
22
 
22
23
  public
23
- NokogiriNonStrictErrorHandler4NekoHtml(boolean nowarning)
24
+ NokogiriNonStrictErrorHandler4NekoHtml(Ruby runtime, boolean nowarning)
24
25
  {
25
- super(false, nowarning);
26
+ super(runtime, false, nowarning);
26
27
  }
27
28
 
28
29
  public
29
- NokogiriNonStrictErrorHandler4NekoHtml(boolean noerror, boolean nowarning)
30
+ NokogiriNonStrictErrorHandler4NekoHtml(Ruby runtime, boolean noerror, boolean nowarning)
30
31
  {
31
- super(noerror, nowarning);
32
+ super(runtime, noerror, nowarning);
32
33
  }
33
34
 
34
35
  public void
@@ -40,13 +41,13 @@ public class NokogiriNonStrictErrorHandler4NekoHtml extends NokogiriErrorHandler
40
41
  public void
41
42
  error(SAXParseException ex) throws SAXException
42
43
  {
43
- errors.add(ex);
44
+ addError(ex);
44
45
  }
45
46
 
46
47
  public void
47
48
  fatalError(SAXParseException ex) throws SAXException
48
49
  {
49
- errors.add(ex);
50
+ addError(ex);
50
51
  }
51
52
 
52
53
  /**
@@ -64,7 +65,7 @@ public class NokogiriNonStrictErrorHandler4NekoHtml extends NokogiriErrorHandler
64
65
  public void
65
66
  error(String domain, String key, XMLParseException e)
66
67
  {
67
- errors.add(e);
68
+ addError(e);
68
69
  }
69
70
 
70
71
  /**
@@ -82,7 +83,7 @@ public class NokogiriNonStrictErrorHandler4NekoHtml extends NokogiriErrorHandler
82
83
  public void
83
84
  fatalError(String domain, String key, XMLParseException e)
84
85
  {
85
- errors.add(e);
86
+ addError(e);
86
87
  }
87
88
 
88
89
  /**
@@ -100,7 +101,7 @@ public class NokogiriNonStrictErrorHandler4NekoHtml extends NokogiriErrorHandler
100
101
  public void
101
102
  warning(String domain, String key, XMLParseException e)
102
103
  {
103
- errors.add(e);
104
+ addError(e);
104
105
  }
105
106
 
106
107
  }
@@ -1,6 +1,7 @@
1
1
  package nokogiri.internals;
2
2
 
3
3
  import org.apache.xerces.xni.parser.XMLParseException;
4
+ import org.jruby.Ruby;
4
5
  import org.xml.sax.SAXException;
5
6
  import org.xml.sax.SAXParseException;
6
7
 
@@ -14,23 +15,23 @@ import org.xml.sax.SAXParseException;
14
15
  public class NokogiriStrictErrorHandler extends NokogiriErrorHandler
15
16
  {
16
17
  public
17
- NokogiriStrictErrorHandler(boolean noerror, boolean nowarning)
18
+ NokogiriStrictErrorHandler(Ruby runtime, boolean noerror, boolean nowarning)
18
19
  {
19
- super(noerror, nowarning);
20
+ super(runtime, noerror, nowarning);
20
21
  }
21
22
 
22
23
  public void
23
24
  warning(SAXParseException spex) throws SAXException
24
25
  {
25
26
  if (!nowarning) { throw spex; }
26
- else { errors.add(spex); }
27
+ else { addError(spex); }
27
28
  }
28
29
 
29
30
  public void
30
31
  error(SAXParseException spex) throws SAXException
31
32
  {
32
33
  if (!noerror) { throw spex; }
33
- else { errors.add(spex); }
34
+ else { addError(spex); }
34
35
  }
35
36
 
36
37
  public void
@@ -43,7 +44,7 @@ public class NokogiriStrictErrorHandler extends NokogiriErrorHandler
43
44
  error(String domain, String key, XMLParseException e) throws XMLParseException
44
45
  {
45
46
  if (!noerror) { throw e; }
46
- else { errors.add(e); }
47
+ else { addError(e); }
47
48
  }
48
49
 
49
50
  public void
@@ -56,6 +57,6 @@ public class NokogiriStrictErrorHandler extends NokogiriErrorHandler
56
57
  warning(String domain, String key, XMLParseException e) throws XMLParseException
57
58
  {
58
59
  if (!nowarning) { throw e; }
59
- if (!usesNekoHtml(domain)) { errors.add(e); }
60
+ else { addError(e); }
60
61
  }
61
62
  }
@@ -673,6 +673,8 @@ public class SaveContextVisitor
673
673
  if (!isEmpty(name) && noEmpty) {
674
674
  buffer.append("</").append(name).append('>');
675
675
  }
676
+ } else if (asXhtml && !isEmpty(name)) {
677
+ buffer.append("</").append(name).append('>');
676
678
  }
677
679
  if (needBreakInClosing(element)) {
678
680
  if (!containsText(element)) { indentation.pop(); }