nokogiri 1.7.2-java → 1.8.0-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 (101) hide show
  1. checksums.yaml +4 -4
  2. data/.cross_rubies +4 -4
  3. data/.travis.yml +43 -24
  4. data/CHANGELOG.md +54 -6
  5. data/Gemfile +8 -7
  6. data/Gemfile-libxml-ruby +3 -0
  7. data/LICENSE-DEPENDENCIES.md +1612 -0
  8. data/{LICENSE.txt → LICENSE.md} +1 -1
  9. data/Manifest.txt +5 -8
  10. data/README.md +8 -5
  11. data/Rakefile +15 -31
  12. data/appveyor.yml +2 -0
  13. data/dependencies.yml +12 -7
  14. data/ext/java/nokogiri/HtmlDocument.java +2 -2
  15. data/ext/java/nokogiri/HtmlSaxParserContext.java +20 -21
  16. data/ext/java/nokogiri/HtmlSaxPushParser.java +6 -10
  17. data/ext/java/nokogiri/NokogiriService.java +10 -31
  18. data/ext/java/nokogiri/XmlAttr.java +1 -26
  19. data/ext/java/nokogiri/XmlCdata.java +0 -1
  20. data/ext/java/nokogiri/XmlComment.java +1 -1
  21. data/ext/java/nokogiri/XmlDocument.java +4 -5
  22. data/ext/java/nokogiri/XmlDocumentFragment.java +29 -21
  23. data/ext/java/nokogiri/XmlDtd.java +1 -1
  24. data/ext/java/nokogiri/XmlElement.java +9 -10
  25. data/ext/java/nokogiri/XmlEntityDecl.java +4 -5
  26. data/ext/java/nokogiri/XmlNode.java +105 -103
  27. data/ext/java/nokogiri/XmlNodeSet.java +64 -76
  28. data/ext/java/nokogiri/XmlReader.java +48 -48
  29. data/ext/java/nokogiri/XmlRelaxng.java +1 -1
  30. data/ext/java/nokogiri/XmlSaxPushParser.java +37 -17
  31. data/ext/java/nokogiri/XmlSchema.java +7 -5
  32. data/ext/java/nokogiri/XmlSyntaxError.java +47 -35
  33. data/ext/java/nokogiri/XmlXpathContext.java +160 -132
  34. data/ext/java/nokogiri/XsltStylesheet.java +15 -24
  35. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +19 -23
  36. data/ext/java/nokogiri/internals/NokogiriDomParser.java +1 -1
  37. data/ext/java/nokogiri/internals/NokogiriEncodingReaderWrapper.java +1 -1
  38. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +11 -13
  39. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +5 -21
  40. data/ext/java/nokogiri/internals/NokogiriHandler.java +1 -1
  41. data/ext/java/nokogiri/internals/NokogiriHelpers.java +105 -142
  42. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +16 -26
  43. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +32 -50
  44. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +10 -13
  45. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +3 -10
  46. data/ext/java/nokogiri/internals/ParserContext.java +4 -8
  47. data/ext/java/nokogiri/internals/ReaderNode.java +53 -93
  48. data/ext/java/nokogiri/internals/SaveContextVisitor.java +77 -89
  49. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +6 -9
  50. data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +167 -0
  51. data/ext/java/nokogiri/internals/XmlDomParserContext.java +17 -6
  52. data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +1 -1
  53. data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +28 -28
  54. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +3 -4
  55. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +2 -2
  56. data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +10 -10
  57. data/ext/java/nokogiri/internals/c14n/ElementProxy.java +5 -5
  58. data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +2 -2
  59. data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +1 -1
  60. data/ext/java/nokogiri/internals/c14n/XMLUtils.java +2 -2
  61. data/ext/java/org/apache/xml/dtm/ref/dom2dtm/DOM2DTMExt.java +1749 -0
  62. data/ext/nokogiri/extconf.rb +12 -17
  63. data/ext/nokogiri/nokogiri.h +0 -10
  64. data/ext/nokogiri/xml_attr.c +12 -8
  65. data/ext/nokogiri/xml_node.c +17 -14
  66. data/ext/nokogiri/xml_sax_push_parser.c +56 -12
  67. data/lib/nokogiri/html/sax/parser.rb +10 -0
  68. data/lib/nokogiri/nokogiri.jar +0 -0
  69. data/lib/nokogiri/version.rb +5 -4
  70. data/lib/nokogiri/xml/document.rb +9 -9
  71. data/lib/nokogiri/xml/node.rb +7 -7
  72. data/lib/nokogiri/xml/node_set.rb +12 -7
  73. data/lib/nokogiri/xml/sax/parser.rb +6 -7
  74. data/lib/nokogiri/xml/searchable.rb +34 -25
  75. data/lib/nokogiri/xml/syntax_error.rb +24 -1
  76. data/test/decorators/test_slop.rb +4 -1
  77. data/test/helper.rb +10 -0
  78. data/test/html/sax/test_parser.rb +27 -0
  79. data/test/html/test_document.rb +12 -1
  80. data/test/html/test_document_encoding.rb +1 -3
  81. data/test/html/test_document_fragment.rb +3 -0
  82. data/test/xml/sax/test_push_parser.rb +48 -0
  83. data/test/xml/test_attr.rb +7 -0
  84. data/test/xml/test_document.rb +1 -1
  85. data/test/xml/test_document_fragment.rb +27 -0
  86. data/test/xml/test_entity_reference.rb +2 -2
  87. data/test/xml/test_node.rb +12 -15
  88. data/test/xml/test_node_reparenting.rb +14 -0
  89. data/test/xml/test_node_set.rb +8 -6
  90. data/test/xml/test_reader.rb +19 -0
  91. data/test/xml/test_syntax_error.rb +21 -15
  92. data/test/xml/test_unparented_node.rb +54 -11
  93. data/test/xml/test_xpath.rb +23 -6
  94. metadata +32 -20
  95. data/ext/java/nokogiri/internals/NokogiriDocumentCache.java +0 -73
  96. data/ext/java/nokogiri/internals/XsltExtensionFunction.java +0 -72
  97. data/suppressions/nokogiri_ree-1.8.7.358.supp +0 -61
  98. data/suppressions/nokogiri_ruby-1.8.7.370.supp +0 -0
  99. data/suppressions/nokogiri_ruby-1.9.2.320.supp +0 -28
  100. data/suppressions/nokogiri_ruby-1.9.3.327.supp +0 -28
  101. data/test_all +0 -105
@@ -223,8 +223,8 @@ def iconv_configure_flags
223
223
 
224
224
  return [
225
225
  '--with-iconv=yes',
226
- *("CPPFLAGS=#{idirs.map { |dir| '-I' << dir }.join(' ')}" if idirs),
227
- *("LDFLAGS=#{ldirs.map { |dir| '-L' << dir }.join(' ')}" if ldirs),
226
+ *("CPPFLAGS=#{idirs.map { |dir| '-I' + dir }.join(' ')}" if idirs),
227
+ *("LDFLAGS=#{ldirs.map { |dir| '-L' + dir }.join(' ')}" if ldirs),
228
228
  ]
229
229
  end
230
230
  end
@@ -260,11 +260,12 @@ end
260
260
 
261
261
  def process_recipe(name, version, static_p, cross_p)
262
262
  MiniPortile.new(name, version).tap do |recipe|
263
- recipe.target = portsdir = File.join(ROOT, "ports")
263
+ recipe.target = File.join(ROOT, "ports")
264
264
  # Prefer host_alias over host in order to use i586-mingw32msvc as
265
265
  # correct compiler prefix for cross build, but use host if not set.
266
266
  recipe.host = RbConfig::CONFIG["host_alias"].empty? ? RbConfig::CONFIG["host"] : RbConfig::CONFIG["host_alias"]
267
267
  recipe.patch_files = Dir[File.join(ROOT, "patches", name, "*.patch")].sort
268
+ recipe.configure_options << "--libdir=#{File.join(recipe.path, "lib")}"
268
269
 
269
270
  yield recipe
270
271
 
@@ -307,7 +308,7 @@ def process_recipe(name, version, static_p, cross_p)
307
308
  if RbConfig::CONFIG['target_cpu'] == 'universal'
308
309
  %w[CFLAGS LDFLAGS].each do |key|
309
310
  unless env[key].include?('-arch')
310
- env[key] << ' ' << RbConfig::CONFIG['ARCH_FLAG']
311
+ env[key] += ' ' + RbConfig::CONFIG['ARCH_FLAG']
311
312
  end
312
313
  end
313
314
  end
@@ -391,7 +392,7 @@ when arg_config('--clean')
391
392
  do_clean
392
393
  end
393
394
 
394
- if openbsd?
395
+ if openbsd? && !using_system_libraries?
395
396
  ENV['CC'] ||= find_executable('egcc') or
396
397
  abort "Please install gcc 4.9+ from ports using `pkg_add -v gcc`"
397
398
  end
@@ -456,7 +457,7 @@ else
456
457
  # The gem version constraint in the Rakefile is not respected at install time.
457
458
  # Keep this version in sync with the one in the Rakefile !
458
459
  require 'rubygems'
459
- gem 'mini_portile2', '~> 2.1.0'
460
+ gem 'mini_portile2', '~> 2.2.0'
460
461
  require 'mini_portile2'
461
462
  message "Using mini_portile version #{MiniPortile::VERSION}\n"
462
463
 
@@ -473,8 +474,8 @@ else
473
474
  if cross_build_p || windows?
474
475
  zlib_recipe = process_recipe("zlib", dependencies["zlib"]["version"], static_p, cross_build_p) do |recipe|
475
476
  recipe.files = [{
476
- url: "http://zlib.net/#{recipe.name}-#{recipe.version}.tar.gz",
477
- md5: dependencies["zlib"]["md5"]
477
+ url: "http://zlib.net/fossils/#{recipe.name}-#{recipe.version}.tar.gz",
478
+ sha256: dependencies["zlib"]["sha256"]
478
479
  }]
479
480
  class << recipe
480
481
  attr_accessor :cross_build_p
@@ -512,7 +513,7 @@ else
512
513
  libiconv_recipe = process_recipe("libiconv", dependencies["libiconv"]["version"], static_p, cross_build_p) do |recipe|
513
514
  recipe.files = [{
514
515
  url: "http://ftp.gnu.org/pub/gnu/libiconv/#{recipe.name}-#{recipe.version}.tar.gz",
515
- md5: dependencies["libiconv"]["md5"]
516
+ sha256: dependencies["libiconv"]["sha256"]
516
517
  }]
517
518
  recipe.configure_options += [
518
519
  "CPPFLAGS=-Wall",
@@ -547,7 +548,7 @@ EOM
547
548
  libxml2_recipe = process_recipe("libxml2", dependencies["libxml2"]["version"], static_p, cross_build_p) do |recipe|
548
549
  recipe.files = [{
549
550
  url: "http://xmlsoft.org/sources/#{recipe.name}-#{recipe.version}.tar.gz",
550
- md5: dependencies["libxml2"]["md5"]
551
+ sha256: dependencies["libxml2"]["sha256"]
551
552
  }]
552
553
  recipe.configure_options += [
553
554
  "--without-python",
@@ -563,7 +564,7 @@ EOM
563
564
  libxslt_recipe = process_recipe("libxslt", dependencies["libxslt"]["version"], static_p, cross_build_p) do |recipe|
564
565
  recipe.files = [{
565
566
  url: "http://xmlsoft.org/sources/#{recipe.name}-#{recipe.version}.tar.gz",
566
- md5: dependencies["libxslt"]["md5"]
567
+ sha256: dependencies["libxslt"]["sha256"]
567
568
  }]
568
569
  recipe.configure_options += [
569
570
  "--without-python",
@@ -657,12 +658,6 @@ have_func('xmlRelaxNGSetValidStructuredErrors')
657
658
  have_func('xmlSchemaSetValidStructuredErrors')
658
659
  have_func('xmlSchemaSetParserStructuredErrors')
659
660
 
660
- if ENV['CPUPROFILE']
661
- unless find_library('profiler', 'ProfilerEnable', *LIB_DIRS)
662
- abort "google performance tools are not installed"
663
- end
664
- end
665
-
666
661
  create_makefile('nokogiri/nokogiri')
667
662
 
668
663
  if enable_config('clean', true)
@@ -34,16 +34,6 @@ int vasprintf (char **strp, const char *fmt, va_list ap);
34
34
  #include <ruby/st.h>
35
35
  #include <ruby/encoding.h>
36
36
 
37
- #ifndef UNUSED
38
- # if defined(__GNUC__)
39
- # define MAYBE_UNUSED(name) name __attribute__((unused))
40
- # define UNUSED(name) MAYBE_UNUSED(UNUSED_ ## name)
41
- # else
42
- # define MAYBE_UNUSED(name) name
43
- # define UNUSED(name) name
44
- # endif
45
- #endif
46
-
47
37
  #ifndef NORETURN
48
38
  # if defined(__GNUC__)
49
39
  # define NORETURN(name) __attribute__((noreturn)) name
@@ -11,11 +11,11 @@ static VALUE set_value(VALUE self, VALUE content)
11
11
  xmlAttrPtr attr;
12
12
  Data_Get_Struct(self, xmlAttr, attr);
13
13
 
14
- if(attr->children) xmlFreeNodeList(attr->children);
14
+ if (attr->children) { xmlFreeNodeList(attr->children); }
15
15
 
16
16
  attr->children = attr->last = NULL;
17
17
 
18
- if(content) {
18
+ if (content) {
19
19
  xmlChar *buffer;
20
20
  xmlNode *tmp;
21
21
 
@@ -30,7 +30,7 @@ static VALUE set_value(VALUE self, VALUE content)
30
30
  for(tmp = attr->children; tmp; tmp = tmp->next) {
31
31
  tmp->parent = (xmlNode *)attr;
32
32
  tmp->doc = attr->doc;
33
- if(tmp->next == NULL) attr->last = tmp;
33
+ if (tmp->next == NULL) { attr->last = tmp; }
34
34
  }
35
35
 
36
36
  /* Free up memory */
@@ -57,20 +57,24 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
57
57
 
58
58
  rb_scan_args(argc, argv, "2*", &document, &name, &rest);
59
59
 
60
+ if (! rb_obj_is_kind_of(document, cNokogiriXmlDocument)) {
61
+ rb_raise(rb_eArgError, "parameter must be a Nokogiri::XML::Document");
62
+ }
63
+
60
64
  Data_Get_Struct(document, xmlDoc, xml_doc);
61
65
 
62
66
  node = xmlNewDocProp(
63
- xml_doc,
64
- (const xmlChar *)StringValueCStr(name),
65
- NULL
66
- );
67
+ xml_doc,
68
+ (const xmlChar *)StringValueCStr(name),
69
+ NULL
70
+ );
67
71
 
68
72
  nokogiri_root_node((xmlNodePtr)node);
69
73
 
70
74
  rb_node = Nokogiri_wrap_xml_node(klass, (xmlNodePtr)node);
71
75
  rb_obj_call_init(rb_node, argc, argv);
72
76
 
73
- if(rb_block_given_p()) rb_yield(rb_node);
77
+ if (rb_block_given_p()) { rb_yield(rb_node); }
74
78
 
75
79
  return rb_node;
76
80
  }
@@ -833,37 +833,40 @@ static VALUE set(VALUE self, VALUE property, VALUE value)
833
833
  static VALUE get(VALUE self, VALUE rattribute)
834
834
  {
835
835
  xmlNodePtr node;
836
- xmlChar* value = 0;
837
- VALUE rvalue ;
838
- char* attribute = 0;
839
- char *colon = 0, *attr_name = 0, *prefix = 0;
836
+ const xmlChar *value = 0;
837
+ VALUE rvalue;
838
+ xmlChar *colon;
839
+ const xmlChar *attribute, *attr_name, *prefix;
840
840
  xmlNsPtr ns;
841
841
 
842
842
  if (NIL_P(rattribute)) return Qnil;
843
843
 
844
844
  Data_Get_Struct(self, xmlNode, node);
845
- attribute = strdup(StringValueCStr(rattribute));
845
+ attribute = xmlCharStrdup(StringValueCStr(rattribute));
846
846
 
847
- colon = strchr(attribute, ':');
847
+ colon = (xmlChar *)xmlStrchr(attribute, (const xmlChar)':');
848
848
  if (colon) {
849
- (*colon) = 0 ; /* create two null-terminated strings of the prefix and attribute name */
850
- prefix = attribute ;
851
- attr_name = colon + 1 ;
852
- ns = xmlSearchNs(node->doc, node, (const xmlChar *)(prefix));
849
+ /* split the attribute string into separate prefix and name by
850
+ * null-terminating the prefix at the colon */
851
+ prefix = attribute;
852
+ attr_name = colon + 1;
853
+ (*colon) = 0;
854
+
855
+ ns = xmlSearchNs(node->doc, node, prefix);
853
856
  if (ns) {
854
- value = xmlGetNsProp(node, (xmlChar*)(attr_name), ns->href);
857
+ value = xmlGetNsProp(node, attr_name, ns->href);
855
858
  } else {
856
859
  value = xmlGetProp(node, (xmlChar*)StringValueCStr(rattribute));
857
860
  }
858
861
  } else {
859
- value = xmlGetNoNsProp(node, (xmlChar*)attribute);
862
+ value = xmlGetNoNsProp(node, attribute);
860
863
  }
861
864
 
862
- free(attribute);
865
+ xmlFree((void *)attribute);
863
866
  if (!value) return Qnil;
864
867
 
865
868
  rvalue = NOKOGIRI_STR_NEW2(value);
866
- xmlFree(value);
869
+ xmlFree((void *)value);
867
870
 
868
871
  return rvalue ;
869
872
  }
@@ -3,7 +3,7 @@
3
3
  static void deallocate(xmlParserCtxtPtr ctx)
4
4
  {
5
5
  NOKOGIRI_DEBUG_START(ctx);
6
- if(ctx != NULL) {
6
+ if (ctx != NULL) {
7
7
  NOKOGIRI_SAX_TUPLE_DESTROY(ctx->userData);
8
8
  xmlFreeParserCtxt(ctx);
9
9
  }
@@ -30,12 +30,12 @@ static VALUE native_write(VALUE self, VALUE _chunk, VALUE _last_chunk)
30
30
 
31
31
  Data_Get_Struct(self, xmlParserCtxt, ctx);
32
32
 
33
- if(Qnil != _chunk) {
33
+ if (Qnil != _chunk) {
34
34
  chunk = StringValuePtr(_chunk);
35
35
  size = (int)RSTRING_LEN(_chunk);
36
36
  }
37
37
 
38
- if(xmlParseChunk(ctx, chunk, size, Qtrue == _last_chunk ? 1 : 0)) {
38
+ if (xmlParseChunk(ctx, chunk, size, Qtrue == _last_chunk ? 1 : 0)) {
39
39
  if (!(ctx->options & XML_PARSE_RECOVER)) {
40
40
  xmlErrorPtr e = xmlCtxtGetLastError(ctx);
41
41
  Nokogiri_error_raise(NULL, e);
@@ -59,17 +59,18 @@ static VALUE initialize_native(VALUE self, VALUE _xml_sax, VALUE _filename)
59
59
 
60
60
  Data_Get_Struct(_xml_sax, xmlSAXHandler, sax);
61
61
 
62
- if(_filename != Qnil) filename = StringValueCStr(_filename);
62
+ if (_filename != Qnil) { filename = StringValueCStr(_filename); }
63
63
 
64
64
  ctx = xmlCreatePushParserCtxt(
65
- sax,
66
- NULL,
67
- NULL,
68
- 0,
69
- filename
70
- );
71
- if(ctx == NULL)
65
+ sax,
66
+ NULL,
67
+ NULL,
68
+ 0,
69
+ filename
70
+ );
71
+ if (ctx == NULL) {
72
72
  rb_raise(rb_eRuntimeError, "Could not create a parser context");
73
+ }
73
74
 
74
75
  ctx->userData = NOKOGIRI_SAX_TUPLE_NEW(ctx, self);
75
76
 
@@ -91,12 +92,53 @@ static VALUE set_options(VALUE self, VALUE options)
91
92
  xmlParserCtxtPtr ctx;
92
93
  Data_Get_Struct(self, xmlParserCtxt, ctx);
93
94
 
94
- if (xmlCtxtUseOptions(ctx, (int)NUM2INT(options)) != 0)
95
+ if (xmlCtxtUseOptions(ctx, (int)NUM2INT(options)) != 0) {
95
96
  rb_raise(rb_eRuntimeError, "Cannot set XML parser context options");
97
+ }
96
98
 
97
99
  return Qnil;
98
100
  }
99
101
 
102
+ /*
103
+ * call-seq:
104
+ * replace_entities
105
+ *
106
+ * Should this parser replace entities? &amp; will get converted to '&' if
107
+ * set to true
108
+ */
109
+ static VALUE get_replace_entities(VALUE self)
110
+ {
111
+ xmlParserCtxtPtr ctx;
112
+ Data_Get_Struct(self, xmlParserCtxt, ctx);
113
+
114
+ if (0 == ctx->replaceEntities) {
115
+ return Qfalse;
116
+ } else {
117
+ return Qtrue;
118
+ }
119
+ }
120
+
121
+ /*
122
+ * call-seq:
123
+ * replace_entities=(boolean)
124
+ *
125
+ * Should this parser replace entities? &amp; will get converted to '&' if
126
+ * set to true
127
+ */
128
+ static VALUE set_replace_entities(VALUE self, VALUE value)
129
+ {
130
+ xmlParserCtxtPtr ctx;
131
+ Data_Get_Struct(self, xmlParserCtxt, ctx);
132
+
133
+ if (Qfalse == value) {
134
+ ctx->replaceEntities = 0;
135
+ } else {
136
+ ctx->replaceEntities = 1;
137
+ }
138
+
139
+ return value;
140
+ }
141
+
100
142
  VALUE cNokogiriXmlSaxPushParser ;
101
143
  void init_xml_sax_push_parser()
102
144
  {
@@ -112,4 +154,6 @@ void init_xml_sax_push_parser()
112
154
  rb_define_private_method(klass, "native_write", native_write, 2);
113
155
  rb_define_method(klass, "options", get_options, 0);
114
156
  rb_define_method(klass, "options=", set_options, 1);
157
+ rb_define_method(klass, "replace_entities", get_replace_entities, 0);
158
+ rb_define_method(klass, "replace_entities=", set_replace_entities, 1);
115
159
  }
@@ -36,6 +36,16 @@ module Nokogiri
36
36
  ctx.parse_with self
37
37
  end
38
38
 
39
+ ###
40
+ # Parse given +io+
41
+ def parse_io io, encoding = 'UTF-8'
42
+ check_encoding(encoding)
43
+ @encoding = encoding
44
+ ctx = ParserContext.io(io, ENCODINGS[encoding])
45
+ yield ctx if block_given?
46
+ ctx.parse_with self
47
+ end
48
+
39
49
  ###
40
50
  # Parse a file with +filename+
41
51
  def parse_file filename, encoding = 'UTF-8'
Binary file
@@ -1,6 +1,6 @@
1
1
  module Nokogiri
2
2
  # The version of Nokogiri you are using
3
- VERSION = '1.7.2'
3
+ VERSION = '1.8.0'
4
4
 
5
5
  class VersionInfo # :nodoc:
6
6
  def jruby?
@@ -12,9 +12,10 @@ module Nokogiri
12
12
  end
13
13
 
14
14
  def loaded_parser_version
15
- LIBXML_PARSER_VERSION.scan(/^(\d+)(\d\d)(\d\d)(?!\d)/).first.collect{ |j|
16
- j.to_i
17
- }.join(".")
15
+ LIBXML_PARSER_VERSION.
16
+ scan(/^(\d+)(\d\d)(\d\d)(?!\d)/).first.
17
+ collect(&:to_i).
18
+ join(".")
18
19
  end
19
20
 
20
21
  def compiled_parser_version
@@ -33,10 +33,11 @@ module Nokogiri
33
33
  # +block+ (optional) is passed a configuration object on which
34
34
  # parse options may be set.
35
35
  #
36
- # When parsing untrusted documents, it's recommended that the
37
- # +nonet+ option be used, as shown in this example code:
38
- #
39
- # Nokogiri::XML::Document.parse(xml_string) { |config| config.nonet }
36
+ # By default, Nokogiri treats documents as untrusted, and so
37
+ # does not attempt to load DTDs or access the network. See
38
+ # Nokogiri::XML::ParseOptions for a complete list of options;
39
+ # and that module's DEFAULT_XML constant for what's set (and not
40
+ # set) by default.
40
41
  #
41
42
  # Nokogiri.XML() is a convenience method which will call this method.
42
43
  #
@@ -239,10 +240,10 @@ module Nokogiri
239
240
  undef_method :namespace_definitions, :line, :add_namespace
240
241
 
241
242
  def add_child node_or_tags
242
- raise "Document already has a root node" if root && root.name != 'nokogiri_text_wrapper'
243
+ raise "A document may not have multiple root nodes." if (root && root.name != 'nokogiri_text_wrapper') && !(node_or_tags.comment? || node_or_tags.processing_instruction?)
243
244
  node_or_tags = coerce(node_or_tags)
244
245
  if node_or_tags.is_a?(XML::NodeSet)
245
- raise "Document cannot have multiple root nodes" if node_or_tags.size > 1
246
+ raise "A document may not have multiple root nodes." if node_or_tags.size > 1
246
247
  super(node_or_tags.first)
247
248
  else
248
249
  super
@@ -273,9 +274,8 @@ module Nokogiri
273
274
  (string_or_io.respond_to?(:eof?) && string_or_io.eof?)
274
275
  end
275
276
 
276
- def implied_xpath_contexts # :nodoc:
277
- ["//"]
278
- end
277
+ # @private
278
+ IMPLIED_XPATH_CONTEXTS = [ '//'.freeze ].freeze # :nodoc:
279
279
 
280
280
  def inspect_attributes
281
281
  [:name, :children]
@@ -154,7 +154,7 @@ module Nokogiri
154
154
  def prepend_child node_or_tags
155
155
  if first = children.first
156
156
  # Mimic the error add_child would raise.
157
- raise RuntimeError, "Document already has a root node" if document? && !node_or_tags.processing_instruction?
157
+ raise RuntimeError, "Document already has a root node" if document? && !(node_or_tags.comment? || node_or_tags.processing_instruction?)
158
158
  first.__send__(:add_sibling, :previous, node_or_tags)
159
159
  else
160
160
  add_child(node_or_tags)
@@ -172,6 +172,7 @@ module Nokogiri
172
172
  add_child node_or_tags
173
173
  self
174
174
  end
175
+
175
176
  ###
176
177
  # Insert +node_or_tags+ before this Node (as a sibling).
177
178
  # +node_or_tags+ can be a Nokogiri::XML::Node, a ::DocumentFragment, a ::NodeSet, or a string containing markup.
@@ -180,7 +181,7 @@ module Nokogiri
180
181
  #
181
182
  # Also see related method +before+.
182
183
  def add_previous_sibling node_or_tags
183
- raise ArgumentError.new("A document may not have multiple root nodes.") if (parent && parent.document?) && !node_or_tags.processing_instruction?
184
+ raise ArgumentError.new("A document may not have multiple root nodes.") if (parent && parent.document?) && !(node_or_tags.comment? || node_or_tags.processing_instruction?)
184
185
 
185
186
  add_sibling :previous, node_or_tags
186
187
  end
@@ -193,7 +194,7 @@ module Nokogiri
193
194
  #
194
195
  # Also see related method +after+.
195
196
  def add_next_sibling node_or_tags
196
- raise ArgumentError.new("A document may not have multiple root nodes.") if (parent && parent.document?) && !node_or_tags.processing_instruction?
197
+ raise ArgumentError.new("A document may not have multiple root nodes.") if (parent && parent.document?) && !(node_or_tags.comment? || node_or_tags.processing_instruction?)
197
198
 
198
199
  add_sibling :next, node_or_tags
199
200
  end
@@ -622,7 +623,7 @@ module Nokogiri
622
623
  encoding = options[:encoding] || document.encoding
623
624
  options[:encoding] = encoding
624
625
 
625
- outstring = ""
626
+ outstring = String.new
626
627
  if encoding && outstring.respond_to?(:force_encoding)
627
628
  outstring.force_encoding(Encoding.find(encoding))
628
629
  end
@@ -818,9 +819,8 @@ Requires a Node, NodeSet or String argument, and cannot accept a #{data.class}.
818
819
  EOERR
819
820
  end
820
821
 
821
- def implied_xpath_contexts # :nodoc:
822
- [".//"]
823
- end
822
+ # @private
823
+ IMPLIED_XPATH_CONTEXTS = [ './/'.freeze ].freeze # :nodoc:
824
824
 
825
825
  def add_child_node_and_reparent_attrs node # :nodoc:
826
826
  add_child_node node