nokogiri 1.6.6.4-java → 1.6.7-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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/.cross_rubies +7 -5
  3. data/.travis.yml +33 -30
  4. data/CHANGELOG.ja.rdoc +38 -6
  5. data/CHANGELOG.rdoc +33 -1
  6. data/Gemfile +3 -2
  7. data/LICENSE.txt +31 -0
  8. data/Manifest.txt +4 -24
  9. data/README.md +170 -0
  10. data/Rakefile +25 -22
  11. data/appveyor.yml +22 -0
  12. data/build_all +6 -90
  13. data/ext/java/nokogiri/XmlDocument.java +5 -0
  14. data/ext/java/nokogiri/XmlNode.java +16 -1
  15. data/ext/java/nokogiri/XmlSaxPushParser.java +6 -2
  16. data/ext/java/nokogiri/XmlSchema.java +20 -20
  17. data/ext/java/nokogiri/internals/NokogiriHandler.java +21 -15
  18. data/ext/java/nokogiri/internals/ParserContext.java +15 -11
  19. data/ext/nokogiri/extconf.rb +37 -34
  20. data/ext/nokogiri/xml_node.c +21 -11
  21. data/ext/nokogiri/xml_sax_parser_context.c +2 -2
  22. data/lib/nokogiri/nokogiri.jar +0 -0
  23. data/lib/nokogiri/version.rb +1 -1
  24. data/lib/nokogiri/xml/node.rb +16 -0
  25. data/{ports/patches → patches}/sort-patches-by-date +0 -0
  26. data/test/html/test_document.rb +26 -3
  27. data/test/xml/sax/test_parser.rb +11 -0
  28. data/test/xml/test_document.rb +11 -0
  29. data/test/xml/test_schema.rb +15 -2
  30. data/test/xml/test_xpath.rb +15 -0
  31. metadata +28 -33
  32. data/README.ja.rdoc +0 -112
  33. data/README.rdoc +0 -177
  34. data/ports/patches/libxml2/0001-Revert-Missing-initialization-for-the-catalog-module.patch +0 -29
  35. data/ports/patches/libxml2/0002-Fix-missing-entities-after-CVE-2014-3660-fix.patch +0 -31
  36. data/ports/patches/libxml2/0003-Stop-parsing-on-entities-boundaries-errors.patch +0 -32
  37. data/ports/patches/libxml2/0004-Cleanup-conditional-section-error-handling.patch +0 -49
  38. data/ports/patches/libxml2/0005-CVE-2015-1819-Enforce-the-reader-to-run-in-constant-.patch +0 -177
  39. data/ports/patches/libxml2/0006-Another-variation-of-overflow-in-Conditional-section.patch +0 -32
  40. data/ports/patches/libxml2/0007-Fix-an-error-in-previous-Conditional-section-patch.patch +0 -28
  41. data/ports/patches/libxml2/0008-CVE-2015-8035-Fix-XZ-compression-support-loop.patch +0 -31
  42. data/ports/patches/libxslt/0001-Adding-doc-update-related-to-1.1.28.patch +0 -222
  43. data/ports/patches/libxslt/0002-Fix-a-couple-of-places-where-f-printf-parameters-wer.patch +0 -53
  44. data/ports/patches/libxslt/0003-Initialize-pseudo-random-number-generator-with-curre.patch +0 -60
  45. data/ports/patches/libxslt/0004-EXSLT-function-str-replace-is-broken-as-is.patch +0 -42
  46. data/ports/patches/libxslt/0006-Fix-str-padding-to-work-with-UTF-8-strings.patch +0 -164
  47. data/ports/patches/libxslt/0007-Separate-function-for-predicate-matching-in-patterns.patch +0 -587
  48. data/ports/patches/libxslt/0008-Fix-direct-pattern-matching.patch +0 -80
  49. data/ports/patches/libxslt/0009-Fix-certain-patterns-with-predicates.patch +0 -185
  50. data/ports/patches/libxslt/0010-Fix-handling-of-UTF-8-strings-in-EXSLT-crypto-module.patch +0 -126
  51. data/ports/patches/libxslt/0013-Memory-leak-in-xsltCompileIdKeyPattern-error-path.patch +0 -25
  52. data/ports/patches/libxslt/0014-Fix-for-bug-436589.patch +0 -43
  53. data/ports/patches/libxslt/0015-Fix-mkdir-for-mingw.patch +0 -41
  54. data/ports/patches/libxslt/0016-Fix-for-type-confusion-in-preprocessing-attributes.patch +0 -29
@@ -37,8 +37,8 @@ import static nokogiri.internals.NokogiriHelpers.getPrefix;
37
37
  import static nokogiri.internals.NokogiriHelpers.isNamespace;
38
38
  import static nokogiri.internals.NokogiriHelpers.stringOrNil;
39
39
 
40
- import java.util.ArrayDeque;
41
40
  import java.util.LinkedList;
41
+ import java.util.Stack;
42
42
 
43
43
  import nokogiri.XmlSyntaxError;
44
44
 
@@ -62,7 +62,7 @@ import org.xml.sax.ext.DefaultHandler2;
62
62
  * @author Yoko Harada <yokolet@gmail.com>
63
63
  */
64
64
  public class NokogiriHandler extends DefaultHandler2 implements XmlDeclHandler {
65
- private StringBuffer buffer;
65
+ Stack<StringBuffer> characterStack;
66
66
  private final Ruby ruby;
67
67
  private final RubyClass attrClass;
68
68
  private final IRubyObject object;
@@ -100,6 +100,7 @@ public class NokogiriHandler extends DefaultHandler2 implements XmlDeclHandler {
100
100
  @Override
101
101
  public void startDocument() throws SAXException {
102
102
  call("start_document");
103
+ characterStack = new Stack();
103
104
  }
104
105
 
105
106
  @Override
@@ -111,6 +112,13 @@ public class NokogiriHandler extends DefaultHandler2 implements XmlDeclHandler {
111
112
 
112
113
  @Override
113
114
  public void endDocument() throws SAXException {
115
+ StringBuffer sb;
116
+ if (!characterStack.empty()) {
117
+ for (int i=0; i<characterStack.size(); i++) {
118
+ sb = characterStack.get(i);
119
+ call("characters", ruby.newString(sb.toString()));
120
+ }
121
+ }
114
122
  call("end_document");
115
123
  }
116
124
 
@@ -120,12 +128,10 @@ public class NokogiriHandler extends DefaultHandler2 implements XmlDeclHandler {
120
128
  }
121
129
 
122
130
  /*
123
- * This has to call either "start_element" or
124
- * "start_element_namespace" depending on whether there are any
125
- * namespace attributes.
131
+ * This calls "start_element_namespace".
126
132
  *
127
133
  * Attributes that define namespaces are passed in a separate
128
- * array of of <code>[:prefix, :uri]</code> arrays and are not
134
+ * array of <code>[:prefix, :uri]</code> arrays and are not
129
135
  * passed with the other attributes.
130
136
  */
131
137
  @Override
@@ -150,7 +156,7 @@ public class NokogiriHandler extends DefaultHandler2 implements XmlDeclHandler {
150
156
 
151
157
  if (isNamespace(qn) && !fromFragmentHandler) {
152
158
  // I haven't figured the reason out yet, but, in somewhere,
153
- // namespace is converted to array in array in array and cause
159
+ // namespace is converted to array in array and cause
154
160
  // TypeError at line 45 in fragment_handler.rb
155
161
  RubyArray ns = RubyArray.newArray(ruby, 2);
156
162
  if (ln.equals("xmlns")) ln = null;
@@ -187,6 +193,7 @@ public class NokogiriHandler extends DefaultHandler2 implements XmlDeclHandler {
187
193
  stringOrNil(ruby, getPrefix(qName)),
188
194
  stringOrNil(ruby, uri),
189
195
  rubyNSAttr);
196
+ characterStack.push(new StringBuffer());
190
197
  }
191
198
 
192
199
  private static String[] emptyAttrs =
@@ -224,6 +231,8 @@ public class NokogiriHandler extends DefaultHandler2 implements XmlDeclHandler {
224
231
 
225
232
  @Override
226
233
  public void endElement(String uri, String localName, String qName) throws SAXException {
234
+ StringBuffer sb = characterStack.pop();
235
+ call("characters", ruby.newString(sb.toString()));
227
236
  call("end_element_namespace",
228
237
  stringOrNil(ruby, localName),
229
238
  stringOrNil(ruby, getPrefix(qName)),
@@ -232,11 +241,8 @@ public class NokogiriHandler extends DefaultHandler2 implements XmlDeclHandler {
232
241
 
233
242
  @Override
234
243
  public void characters(char[] ch, int start, int length) throws SAXException {
235
- if (buffer != null) {
236
- buffer.append(new String(ch, start, length));
237
- } else {
238
- call("characters", ruby.newString(new String(ch, start, length)));
239
- }
244
+ StringBuffer sb = characterStack.peek();
245
+ sb.append(new String(ch, start, length));
240
246
  }
241
247
 
242
248
  @Override
@@ -246,13 +252,13 @@ public class NokogiriHandler extends DefaultHandler2 implements XmlDeclHandler {
246
252
 
247
253
  @Override
248
254
  public void startCDATA() throws SAXException {
249
- buffer = new StringBuffer();
255
+ characterStack.push(new StringBuffer());
250
256
  }
251
257
 
252
258
  @Override
253
259
  public void endCDATA() throws SAXException {
254
- call("cdata_block", ruby.newString(buffer.toString()));
255
- buffer = null;
260
+ StringBuffer sb = characterStack.pop();
261
+ call("cdata_block", ruby.newString(sb.toString()));
256
262
  }
257
263
 
258
264
  @Override
@@ -100,25 +100,29 @@ public class ParserContext extends RubyObject {
100
100
  RubyString stringData = null;
101
101
  if (invoke(context, data, "respond_to?",
102
102
  ruby.newSymbol("to_io").to_sym()).isTrue()) {
103
- /* IO or other object that responds to :to_io */
104
103
  RubyIO io =
105
104
  (RubyIO) TypeConverter.convertToType(data,
106
105
  ruby.getIO(),
107
106
  "to_io");
108
107
  // use unclosedable input stream to fix #495
109
108
  source.setByteStream(new UncloseableInputStream(io.getInStream()));
110
- } else {
111
- if (invoke(context, data, "respond_to?",
109
+
110
+ } else if (invoke(context, data, "respond_to?",
111
+ ruby.newSymbol("read").to_sym()).isTrue()) {
112
+ stringData = invoke(context, data, "read").convertToString();
113
+
114
+ } else if (invoke(context, data, "respond_to?",
112
115
  ruby.newSymbol("string").to_sym()).isTrue()) {
113
- /* StringIO or other object that responds to :string */
114
- stringData = invoke(context, data, "string").convertToString();
115
- } else if (data instanceof RubyString) {
116
- stringData = (RubyString) data;
117
- } else {
118
- throw ruby.newArgumentError(
119
- "must be kind_of String or respond to :to_io or :string");
120
- }
116
+ stringData = invoke(context, data, "string").convertToString();
117
+
118
+ } else if (data instanceof RubyString) {
119
+ stringData = (RubyString) data;
120
+
121
+ } else {
122
+ throw ruby.newArgumentError(
123
+ "must be kind_of String or respond to :to_io, :read, or :string");
121
124
  }
125
+
122
126
  if (stringData != null) {
123
127
  String encName = null;
124
128
  if (stringData.encoding(context) != null) {
@@ -148,8 +148,8 @@ def iconv_configure_flags
148
148
 
149
149
  return [
150
150
  '--with-iconv=yes',
151
- *("CPPFLAGS=#{idirs.map { |dir| '-I' << dir }.join(' ')}".quote if idirs),
152
- *("LDFLAGS=#{ldirs.map { |dir| '-L' << dir }.join(' ')}".quote if ldirs),
151
+ *("CPPFLAGS=#{idirs.map { |dir| '-I' << dir }.join(' ')}" if idirs),
152
+ *("LDFLAGS=#{ldirs.map { |dir| '-L' << dir }.join(' ')}" if ldirs),
153
153
  ]
154
154
  end
155
155
  }
@@ -164,22 +164,32 @@ def iconv_configure_flags
164
164
 
165
165
  return [
166
166
  '--with-iconv=yes',
167
- "CPPFLAGS=#{cflags}".quote,
168
- "LDFLAGS=#{ldflags}".quote,
169
- "LIBS=#{libs}".quote,
167
+ "CPPFLAGS=#{cflags}",
168
+ "LDFLAGS=#{ldflags}",
169
+ "LIBS=#{libs}",
170
170
  ]
171
171
  end
172
172
 
173
173
  asplode "libiconv"
174
174
  end
175
175
 
176
+ # When using rake-compiler-dock on Windows, the underlying Virtualbox shared
177
+ # folders don't support symlinks, but libiconv expects it for a build on
178
+ # Linux. We work around this limitation by using the temp dir for cooking.
179
+ def chdir_for_build
180
+ build_dir = ENV['RCD_HOST_RUBY_PLATFORM'].to_s =~ /mingw|mswin|cygwin/ ? '/tmp' : '.'
181
+ Dir.chdir(build_dir) do
182
+ yield
183
+ end
184
+ end
185
+
176
186
  def process_recipe(name, version, static_p, cross_p)
177
187
  MiniPortile.new(name, version).tap do |recipe|
178
188
  recipe.target = portsdir = File.join(ROOT, "ports")
179
189
  # Prefer host_alias over host in order to use i586-mingw32msvc as
180
190
  # correct compiler prefix for cross build, but use host if not set.
181
191
  recipe.host = RbConfig::CONFIG["host_alias"].empty? ? RbConfig::CONFIG["host"] : RbConfig::CONFIG["host_alias"]
182
- recipe.patch_files = Dir[File.join(portsdir, "patches", name, "*.patch")].sort
192
+ recipe.patch_files = Dir[File.join(ROOT, "patches", name, "*.patch")].sort
183
193
 
184
194
  yield recipe
185
195
 
@@ -190,7 +200,7 @@ def process_recipe(name, version, static_p, cross_p)
190
200
  recipe.configure_options.flatten!
191
201
 
192
202
  recipe.configure_options.delete_if { |option|
193
- case option.shellsplit.first
203
+ case option
194
204
  when /\A(\w+)=(.*)\z/
195
205
  env[$1] = $2
196
206
  true
@@ -221,14 +231,14 @@ def process_recipe(name, version, static_p, cross_p)
221
231
 
222
232
  if RbConfig::CONFIG['target_cpu'] == 'universal'
223
233
  %w[CFLAGS LDFLAGS].each { |key|
224
- unless env[key].shellsplit.include?('-arch')
234
+ unless env[key].include?('-arch')
225
235
  env[key] << ' ' << RbConfig::CONFIG['ARCH_FLAG']
226
236
  end
227
237
  }
228
238
  end
229
239
 
230
240
  recipe.configure_options += env.map { |key, value|
231
- "#{key}=#{value}".shellescape
241
+ "#{key}=#{value}"
232
242
  }
233
243
 
234
244
  message <<-"EOS"
@@ -275,7 +285,9 @@ versions of libxml2 provided by OS/package vendors.
275
285
 
276
286
  checkpoint = "#{recipe.target}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
277
287
  unless File.exist?(checkpoint)
278
- recipe.cook
288
+ chdir_for_build do
289
+ recipe.cook
290
+ end
279
291
  FileUtils.touch checkpoint
280
292
  end
281
293
  recipe.activate
@@ -301,19 +313,6 @@ end
301
313
  # https://bugs.ruby-lang.org/issues/8074
302
314
  @libdir_basename = "lib" if RUBY_VERSION < '2.1.0'
303
315
 
304
- # Workaround for #1102
305
- def monkey_patch_mini_portile
306
- MiniPortile.class_eval do
307
- def patch
308
- @patch_files.each do |full_path|
309
- next unless File.exists?(full_path)
310
- output "Running patch with #{full_path}..."
311
- execute('patch', %Q(patch -p1 < "#{full_path}"))
312
- end
313
- end
314
- end
315
- end
316
-
317
316
  #
318
317
  # main
319
318
  #
@@ -392,8 +391,12 @@ when using_system_libraries?
392
391
  else
393
392
  message "Building nokogiri using packaged libraries.\n"
394
393
 
395
- require 'mini_portile'
396
- monkey_patch_mini_portile
394
+ # The gem version constraint in the Rakefile is not respected at install time.
395
+ # Keep this version in sync with the one in the Rakefile !
396
+ gem "mini_portile2", "~> 2.0.0.rc2"
397
+ require 'mini_portile2'
398
+ message "Using mini_portile version #{MiniPortile::VERSION}\n"
399
+
397
400
  require 'yaml'
398
401
 
399
402
  static_p = enable_config('static', true) or
@@ -443,17 +446,17 @@ else
443
446
  libiconv_recipe = process_recipe("libiconv", dependencies["libiconv"], static_p, cross_build_p) do |recipe|
444
447
  recipe.files = ["http://ftp.gnu.org/pub/gnu/libiconv/#{recipe.name}-#{recipe.version}.tar.gz"]
445
448
  recipe.configure_options += [
446
- "CPPFLAGS='-Wall'",
447
- "CFLAGS='-O2 -g'",
448
- "CXXFLAGS='-O2 -g'",
449
+ "CPPFLAGS=-Wall",
450
+ "CFLAGS=-O2 -g",
451
+ "CXXFLAGS=-O2 -g",
449
452
  "LDFLAGS="
450
453
  ]
451
454
  end
452
455
  else
453
- if darwin_p && !File.exist?('/usr/include/iconv.h')
456
+ if darwin_p && !have_header('iconv.h')
454
457
  abort <<'EOM'.chomp
455
458
  -----
456
- The file "/usr/include/iconv.h" is missing in your build environment,
459
+ The file "iconv.h" is missing in your build environment,
457
460
  which means you haven't installed Xcode Command Line Tools properly.
458
461
 
459
462
  To install Command Line Tools, try running `xcode-select --install` on
@@ -473,7 +476,7 @@ EOM
473
476
  end
474
477
 
475
478
  libxml2_recipe = process_recipe("libxml2", dependencies["libxml2"], static_p, cross_build_p) do |recipe|
476
- recipe.files = ["ftp://ftp.xmlsoft.org/libxml2/#{recipe.name}-#{recipe.version}.tar.gz"]
479
+ recipe.files = ["http://xmlsoft.org/sources/#{recipe.name}-#{recipe.version}.tar.gz"]
477
480
  recipe.configure_options += [
478
481
  "--without-python",
479
482
  "--without-readline",
@@ -485,7 +488,7 @@ EOM
485
488
  end
486
489
 
487
490
  libxslt_recipe = process_recipe("libxslt", dependencies["libxslt"], static_p, cross_build_p) do |recipe|
488
- recipe.files = ["ftp://ftp.xmlsoft.org/libxml2/#{recipe.name}-#{recipe.version}.tar.gz"]
491
+ recipe.files = ["http://xmlsoft.org/sources/#{recipe.name}-#{recipe.version}.tar.gz"]
489
492
  recipe.configure_options += [
490
493
  "--without-python",
491
494
  "--without-crypto",
@@ -526,8 +529,8 @@ EOM
526
529
  }
527
530
 
528
531
  # Defining a macro that expands to a C string; double quotes are significant.
529
- $CPPFLAGS << ' ' << "-DNOKOGIRI_#{recipe.name.upcase}_PATH=\"#{recipe.path}\"".shellescape
530
- $CPPFLAGS << ' ' << "-DNOKOGIRI_#{recipe.name.upcase}_PATCHES=\"#{recipe.patch_files.map { |path| File.basename(path) }.join(' ')}\"".shellescape
532
+ $CPPFLAGS << ' ' << "-DNOKOGIRI_#{recipe.name.upcase}_PATH=\"#{recipe.path}\"".inspect
533
+ $CPPFLAGS << ' ' << "-DNOKOGIRI_#{recipe.name.upcase}_PATCHES=\"#{recipe.patch_files.map { |path| File.basename(path) }.join(' ')}\"".inspect
531
534
 
532
535
  case libname
533
536
  when 'xml2'
@@ -778,11 +778,19 @@ static VALUE namespaced_key_eh(VALUE self, VALUE attribute, VALUE namespace)
778
778
  *
779
779
  * Set the +property+ to +value+
780
780
  */
781
- static VALUE set(VALUE self, VALUE property, VALUE value)
781
+ static VALUE set(VALUE node_rb, VALUE property_name_rb, VALUE property_value_rb)
782
782
  {
783
783
  xmlNodePtr node, cur;
784
- xmlAttrPtr prop;
785
- Data_Get_Struct(self, xmlNode, node);
784
+ xmlChar* property_name ;
785
+ xmlAttrPtr property;
786
+
787
+ Data_Get_Struct(node_rb, xmlNode, node);
788
+
789
+ if (node->type != XML_ELEMENT_NODE) {
790
+ return(Qnil); // TODO: would raising an exception be more appropriate?
791
+ }
792
+
793
+ property_name = (xmlChar *)StringValuePtr(property_name_rb);
786
794
 
787
795
  /* If a matching attribute node already exists, then xmlSetProp will destroy
788
796
  * the existing node's children. However, if Nokogiri has a node object
@@ -790,11 +798,9 @@ static VALUE set(VALUE self, VALUE property, VALUE value)
790
798
  *
791
799
  * We can avoid this by unlinking these nodes first.
792
800
  */
793
- if (node->type != XML_ELEMENT_NODE)
794
- return(Qnil);
795
- prop = xmlHasProp(node, (xmlChar *)StringValuePtr(property));
796
- if (prop && prop->children) {
797
- for (cur = prop->children; cur; cur = cur->next) {
801
+ property = xmlHasProp(node, property_name);
802
+ if (property && property->children) {
803
+ for (cur = property->children; cur; cur = cur->next) {
798
804
  if (cur->_private) {
799
805
  nokogiri_root_node(cur);
800
806
  xmlUnlinkNode(cur);
@@ -802,10 +808,14 @@ static VALUE set(VALUE self, VALUE property, VALUE value)
802
808
  }
803
809
  }
804
810
 
805
- xmlSetProp(node, (xmlChar *)StringValuePtr(property),
806
- (xmlChar *)StringValuePtr(value));
811
+ xmlResetLastError();
812
+ xmlSetStructuredErrorFunc(NULL, Nokogiri_error_silencer);
813
+
814
+ xmlSetProp(node, property_name, (xmlChar *)StringValuePtr(property_value_rb));
815
+
816
+ xmlSetStructuredErrorFunc(NULL, NULL);
807
817
 
808
- return value;
818
+ return property_value_rb;
809
819
  }
810
820
 
811
821
  /*
@@ -206,7 +206,7 @@ static VALUE column(VALUE self)
206
206
  * recovery=(boolean)
207
207
  *
208
208
  * Should this parser recover from structural errors? It will not stop processing
209
- * file on structural errors if if set to true
209
+ * file on structural errors if set to true
210
210
  */
211
211
  static VALUE set_recovery(VALUE self, VALUE value)
212
212
  {
@@ -226,7 +226,7 @@ static VALUE set_recovery(VALUE self, VALUE value)
226
226
  * recovery
227
227
  *
228
228
  * Should this parser recover from structural errors? It will not stop processing
229
- * file on structural errors if if set to true
229
+ * file on structural errors if set to true
230
230
  */
231
231
  static VALUE get_recovery(VALUE self)
232
232
  {
Binary file
@@ -1,6 +1,6 @@
1
1
  module Nokogiri
2
2
  # The version of Nokogiri you are using
3
- VERSION = '1.6.6.4'
3
+ VERSION = '1.6.7'
4
4
 
5
5
  class VersionInfo # :nodoc:
6
6
  def jruby?
@@ -32,6 +32,22 @@ module Nokogiri
32
32
  # * Nokogiri::XML::Node#next
33
33
  # * Nokogiri::XML::Node#previous
34
34
  #
35
+ #
36
+ # When printing or otherwise emitting a document or a node (and
37
+ # its subtree), there are a few methods you might want to use:
38
+ #
39
+ # * content, text, inner_text, to_str: emit plaintext
40
+ #
41
+ # These methods will all emit the plaintext version of your
42
+ # document, meaning that entities will be replaced (e.g., "&lt;"
43
+ # will be replaced with "<"), meaning that any sanitizing will
44
+ # likely be un-done in the output.
45
+ #
46
+ # * to_s, to_xml, to_html, inner_html: emit well-formed markup
47
+ #
48
+ # These methods will all emit properly-escaped markup, meaning
49
+ # that it's suitable for consumption by browsers, parsers, etc.
50
+ #
35
51
  # You may search this node's subtree using Searchable#xpath and Searchable#css
36
52
  class Node
37
53
  include Nokogiri::XML::PP::Node
File without changes
@@ -14,6 +14,11 @@ module Nokogiri
14
14
  assert @html.xpath(nil)
15
15
  end
16
16
 
17
+ def test_does_not_fail_with_illformatted_html
18
+ doc = Nokogiri::HTML('"</html>";'.force_encoding(Encoding::BINARY))
19
+ assert_not_nil doc
20
+ end
21
+
17
22
  def test_exceptions_remove_newlines
18
23
  errors = @html.errors
19
24
  assert errors.length > 0, 'has errors'
@@ -88,9 +93,9 @@ module Nokogiri
88
93
  def test_document_parse_method_with_url
89
94
  require 'open-uri'
90
95
  begin
91
- html = open('http://google.com').read
92
- rescue
93
- skip("This test needs the internet. Skips if no internet available.")
96
+ html = open('https://www.yahoo.com').read
97
+ rescue Exception => e
98
+ skip("This test needs the internet. Skips if no internet available. (#{e})")
94
99
  end
95
100
  doc = Nokogiri::HTML html ,"http:/foobar.foobar/"
96
101
  refute_empty doc.to_s, "Document should not be empty"
@@ -637,6 +642,24 @@ eohtml
637
642
  assert_equal original_errors.length+1, doc1.errors.length
638
643
  assert_match(/ID unique already defined/, doc1.errors.last.to_s)
639
644
  end
645
+
646
+ def test_silencing_nonparse_errors_during_attribute_insertion_1262
647
+ # see https://github.com/sparklemotion/nokogiri/issues/1262
648
+ #
649
+ # libxml2 emits a warning when this happens; the JRuby
650
+ # implementation does not. so rather than capture the error in
651
+ # doc.errors in a platform-dependent way, I'm opting to have
652
+ # the error silenced.
653
+ #
654
+ # So this test doesn't look meaningful, but we want to avoid
655
+ # having `ID unique-issue-1262 already defined` emitted to
656
+ # stderr when running the test suite.
657
+ #
658
+ doc = Nokogiri::HTML::Document.new
659
+ Nokogiri::XML::Element.new("div", doc).set_attribute('id', 'unique-issue-1262')
660
+ Nokogiri::XML::Element.new("div", doc).set_attribute('id', 'unique-issue-1262')
661
+ assert_equal 0, doc.errors.length
662
+ end
640
663
  end
641
664
  end
642
665
  end