nokogiri 1.6.1-java → 1.6.2-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 (137) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +17 -0
  3. data/.travis.yml +6 -6
  4. data/CHANGELOG.ja.rdoc +61 -8
  5. data/CHANGELOG.rdoc +58 -3
  6. data/Gemfile +3 -3
  7. data/Manifest.txt +57 -1
  8. data/README.ja.rdoc +22 -17
  9. data/README.rdoc +23 -18
  10. data/ROADMAP.md +1 -2
  11. data/Rakefile +162 -58
  12. data/build_all +56 -31
  13. data/dependencies.yml +3 -3
  14. data/ext/java/nokogiri/NokogiriService.java +9 -5
  15. data/ext/java/nokogiri/XmlDocument.java +95 -54
  16. data/ext/java/nokogiri/XmlNode.java +93 -42
  17. data/ext/java/nokogiri/XmlReader.java +1 -1
  18. data/ext/java/nokogiri/XmlSaxParserContext.java +33 -0
  19. data/ext/java/nokogiri/XmlSchema.java +4 -2
  20. data/ext/java/nokogiri/XmlXpathContext.java +118 -76
  21. data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +20 -0
  22. data/ext/java/nokogiri/internals/NokogiriHandler.java +3 -10
  23. data/ext/java/nokogiri/internals/NokogiriHelpers.java +40 -23
  24. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +59 -54
  25. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +1 -1
  26. data/ext/java/nokogiri/internals/ParserContext.java +1 -4
  27. data/ext/java/nokogiri/internals/SaveContextVisitor.java +6 -2
  28. data/ext/java/nokogiri/internals/c14n/AttrCompare.java +119 -0
  29. data/ext/java/nokogiri/internals/c14n/C14nHelper.java +159 -0
  30. data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +37 -0
  31. data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +93 -0
  32. data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +252 -0
  33. data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +639 -0
  34. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +38 -0
  35. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +38 -0
  36. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +368 -0
  37. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +295 -0
  38. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +40 -0
  39. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +44 -0
  40. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +44 -0
  41. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +43 -0
  42. data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +630 -0
  43. data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +173 -0
  44. data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +76 -0
  45. data/ext/java/nokogiri/internals/c14n/Constants.java +42 -0
  46. data/ext/java/nokogiri/internals/c14n/ElementProxy.java +293 -0
  47. data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +93 -0
  48. data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +79 -0
  49. data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +165 -0
  50. data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +76 -0
  51. data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +402 -0
  52. data/ext/java/nokogiri/internals/c14n/NodeFilter.java +51 -0
  53. data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +179 -0
  54. data/ext/java/nokogiri/internals/c14n/XMLUtils.java +507 -0
  55. data/ext/nokogiri/extconf.rb +429 -128
  56. data/ext/nokogiri/html_document.c +2 -2
  57. data/ext/nokogiri/nokogiri.c +6 -1
  58. data/ext/nokogiri/xml_document.c +5 -4
  59. data/ext/nokogiri/xml_node.c +76 -7
  60. data/ext/nokogiri/xml_reader.c +1 -1
  61. data/ext/nokogiri/xml_sax_parser_context.c +40 -0
  62. data/ext/nokogiri/xml_syntax_error.c +10 -5
  63. data/ext/nokogiri/xml_syntax_error.h +1 -1
  64. data/ext/nokogiri/xml_xpath_context.c +2 -14
  65. data/ext/nokogiri/xslt_stylesheet.c +1 -1
  66. data/lib/nokogiri.rb +31 -22
  67. data/lib/nokogiri/css/node.rb +0 -50
  68. data/lib/nokogiri/css/parser.rb +213 -218
  69. data/lib/nokogiri/css/parser.y +21 -30
  70. data/lib/nokogiri/css/xpath_visitor.rb +62 -14
  71. data/lib/nokogiri/html/document.rb +97 -18
  72. data/lib/nokogiri/html/sax/parser.rb +2 -2
  73. data/lib/nokogiri/nokogiri.jar +0 -0
  74. data/lib/nokogiri/version.rb +1 -1
  75. data/lib/nokogiri/xml/builder.rb +1 -1
  76. data/lib/nokogiri/xml/document.rb +2 -2
  77. data/lib/nokogiri/xml/dtd.rb +10 -0
  78. data/lib/nokogiri/xml/node.rb +26 -1
  79. data/lib/nokogiri/xml/sax/parser.rb +1 -1
  80. data/ports/patches/libxml2/0001-Fix-parser-local-buffers-size-problems.patch +265 -0
  81. data/ports/patches/libxml2/0002-Fix-entities-local-buffers-size-problems.patch +102 -0
  82. data/ports/patches/libxml2/0003-Fix-an-error-in-previous-commit.patch +26 -0
  83. data/ports/patches/libxml2/0004-Fix-potential-out-of-bound-access.patch +26 -0
  84. data/ports/patches/libxml2/0005-Detect-excessive-entities-expansion-upon-replacement.patch +158 -0
  85. data/ports/patches/libxml2/0006-Do-not-fetch-external-parsed-entities.patch +78 -0
  86. data/ports/patches/libxml2/0007-Enforce-XML_PARSER_EOF-state-handling-through-the-pa.patch +480 -0
  87. data/ports/patches/libxml2/0008-Improve-handling-of-xmlStopParser.patch +315 -0
  88. data/ports/patches/libxml2/0009-Fix-a-couple-of-return-without-value.patch +37 -0
  89. data/ports/patches/libxslt/0001-Adding-doc-update-related-to-1.1.28.patch +222 -0
  90. data/ports/patches/libxslt/0002-Fix-a-couple-of-places-where-f-printf-parameters-wer.patch +53 -0
  91. data/ports/patches/libxslt/0003-Initialize-pseudo-random-number-generator-with-curre.patch +60 -0
  92. data/ports/patches/libxslt/0004-EXSLT-function-str-replace-is-broken-as-is.patch +42 -0
  93. data/ports/patches/libxslt/0006-Fix-str-padding-to-work-with-UTF-8-strings.patch +164 -0
  94. data/ports/patches/libxslt/0007-Separate-function-for-predicate-matching-in-patterns.patch +587 -0
  95. data/ports/patches/libxslt/0008-Fix-direct-pattern-matching.patch +80 -0
  96. data/ports/patches/libxslt/0009-Fix-certain-patterns-with-predicates.patch +185 -0
  97. data/ports/patches/libxslt/0010-Fix-handling-of-UTF-8-strings-in-EXSLT-crypto-module.patch +126 -0
  98. data/ports/patches/libxslt/0013-Memory-leak-in-xsltCompileIdKeyPattern-error-path.patch +25 -0
  99. data/ports/patches/libxslt/0014-Fix-for-bug-436589.patch +43 -0
  100. data/ports/patches/libxslt/0015-Fix-mkdir-for-mingw.patch +41 -0
  101. data/suppressions/README.txt +1 -0
  102. data/suppressions/nokogiri_ree-1.8.7.358.supp +61 -0
  103. data/suppressions/nokogiri_ruby-1.8.7.370.supp +0 -0
  104. data/suppressions/nokogiri_ruby-1.9.2.320.supp +28 -0
  105. data/suppressions/nokogiri_ruby-1.9.3.327.supp +28 -0
  106. data/test/css/test_nthiness.rb +65 -2
  107. data/test/css/test_parser.rb +27 -10
  108. data/test/css/test_tokenizer.rb +1 -1
  109. data/test/css/test_xpath_visitor.rb +6 -1
  110. data/test/files/atom.xml +344 -0
  111. data/test/files/shift_jis_no_charset.html +9 -0
  112. data/test/helper.rb +10 -0
  113. data/test/html/test_document.rb +74 -7
  114. data/test/html/test_document_encoding.rb +10 -0
  115. data/test/html/test_document_fragment.rb +9 -3
  116. data/test/namespaces/test_namespaces_aliased_default.rb +24 -0
  117. data/test/namespaces/test_namespaces_in_cloned_doc.rb +31 -0
  118. data/test/namespaces/test_namespaces_preservation.rb +31 -0
  119. data/test/test_nokogiri.rb +6 -0
  120. data/test/test_reader.rb +7 -4
  121. data/test/test_xslt_transforms.rb +25 -0
  122. data/test/xml/sax/test_parser.rb +16 -0
  123. data/test/xml/sax/test_parser_context.rb +9 -0
  124. data/test/xml/test_builder.rb +9 -0
  125. data/test/xml/test_c14n.rb +12 -2
  126. data/test/xml/test_document.rb +66 -0
  127. data/test/xml/test_document_fragment.rb +5 -0
  128. data/test/xml/test_dtd.rb +84 -0
  129. data/test/xml/test_entity_reference.rb +3 -3
  130. data/test/xml/test_node.rb +21 -3
  131. data/test/xml/test_node_attributes.rb +17 -0
  132. data/test/xml/test_schema.rb +26 -0
  133. data/test/xml/test_text.rb +15 -0
  134. data/test/xml/test_xpath.rb +87 -0
  135. data/test_all +3 -3
  136. metadata +119 -68
  137. data/tasks/cross_compile.rb +0 -134
@@ -26,6 +26,13 @@ module Nokogiri
26
26
  assert doc.root
27
27
  end
28
28
 
29
+ # issue #1005
30
+ def test_strict_parsing_empty_doc_should_raise_exception
31
+ assert_raises(SyntaxError) do
32
+ Nokogiri::XML(StringIO.new('')) { |c| c.strict }
33
+ end
34
+ end
35
+
29
36
  # issue #838
30
37
  def test_document_with_invalid_prolog
31
38
  doc = Nokogiri::XML '<? ?>'
@@ -337,6 +344,59 @@ module Nokogiri
337
344
  assert_equal "quack!", doc.root.children.first.content
338
345
  end
339
346
 
347
+ def test_prepend
348
+ doc = Nokogiri::XML('<root>')
349
+
350
+ node_set = doc.root.prepend_child '<branch/>'
351
+ assert_equal %w[branch], node_set.map(&:name)
352
+
353
+ branch = doc.at('//branch')
354
+
355
+ leaves = %w[leaf1 leaf2 leaf3]
356
+ leaves.each { |name|
357
+ branch.prepend_child('<%s/>' % name)
358
+ }
359
+ assert_equal leaves.length, branch.children.length
360
+ assert_equal leaves.reverse, branch.children.map(&:name)
361
+ end
362
+
363
+ def test_prepend_child_fragment_with_single_node
364
+ doc = Nokogiri::XML::Document.new
365
+ fragment = doc.fragment('<hello />')
366
+ doc.prepend_child fragment
367
+ assert_equal '/hello', doc.at('//hello').path
368
+ assert_equal 'hello', doc.root.name
369
+ end
370
+
371
+ def test_prepend_child_fragment_with_multiple_nodes
372
+ doc = Nokogiri::XML::Document.new
373
+ fragment = doc.fragment('<hello /><goodbye />')
374
+ assert_raises(RuntimeError) do
375
+ doc.prepend_child fragment
376
+ end
377
+ end
378
+
379
+ def test_prepend_child_fragment_with_multiple_nodes
380
+ doc = Nokogiri::XML::Document.new
381
+ fragment = doc.fragment('<hello /><goodbye />')
382
+ assert_raises(RuntimeError) do
383
+ doc.prepend_child fragment
384
+ end
385
+ end
386
+
387
+ def test_prepend_child_with_multiple_roots
388
+ assert_raises(RuntimeError) do
389
+ @xml.prepend_child Node.new('foo', @xml)
390
+ end
391
+ end
392
+
393
+ def test_prepend_child_with_string
394
+ doc = Nokogiri::XML::Document.new
395
+ doc.prepend_child "<div>quack!</div>"
396
+ assert_equal 1, doc.root.children.length
397
+ assert_equal "quack!", doc.root.children.first.content
398
+ end
399
+
340
400
  def test_move_root_to_document_with_no_root
341
401
  sender = Nokogiri::XML('<root>foo</root>')
342
402
  newdoc = Nokogiri::XML::Document.new
@@ -483,6 +543,12 @@ module Nokogiri
483
543
  }
484
544
  end
485
545
 
546
+ def test_xpath_syntax_error
547
+ assert_raises(Nokogiri::XML::XPath::SyntaxError) do
548
+ @xml.xpath('\\')
549
+ end
550
+ end
551
+
486
552
  def test_ancestors
487
553
  assert_equal 0, @xml.ancestors.length
488
554
  end
@@ -76,6 +76,11 @@ module Nokogiri
76
76
  assert_instance_of klass, doc
77
77
  end
78
78
 
79
+ def test_unparented_text_node_parse
80
+ fragment = Nokogiri::XML::DocumentFragment.parse("foo")
81
+ fragment.children.after("<bar/>")
82
+ end
83
+
79
84
  def test_xml_fragment
80
85
  fragment = Nokogiri::XML.fragment("<div>a</div>")
81
86
  assert_equal "<div>a</div>", fragment.to_s
@@ -19,6 +19,90 @@ module Nokogiri
19
19
  assert_equal 'bar', dtd.external_id
20
20
  end
21
21
 
22
+ def test_html_dtd
23
+ {
24
+ 'MathML 2.0' => [
25
+ '<!DOCTYPE math PUBLIC "-//W3C//DTD MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd">',
26
+ false,
27
+ false,
28
+ ],
29
+ 'HTML 2.0' => [
30
+ '<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">',
31
+ true,
32
+ false,
33
+ ],
34
+ 'HTML 3.2' => [
35
+ '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">',
36
+ true,
37
+ false,
38
+ ],
39
+ 'XHTML Basic 1.0' => [
40
+ '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">',
41
+ true,
42
+ false,
43
+ ],
44
+ 'XHTML 1.0 Strict' => [
45
+ '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
46
+ true,
47
+ false,
48
+ ],
49
+ 'XHTML + MathML + SVG Profile (XHTML as the host language)' => [
50
+ '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">',
51
+ true,
52
+ false,
53
+ ],
54
+ 'XHTML + MathML + SVG Profile (Using SVG as the host)' => [
55
+ '<!DOCTYPE svg:svg PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">',
56
+ false,
57
+ false,
58
+ ],
59
+ 'CHTML 1.0' => [
60
+ '<!DOCTYPE HTML PUBLIC "-//W3C//DTD Compact HTML 1.0 Draft//EN">',
61
+ true,
62
+ false,
63
+ ],
64
+ 'HTML 4.01 Strict' => [
65
+ '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
66
+ true,
67
+ false,
68
+ ],
69
+ 'HTML 4.01 Transitional' => [
70
+ '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
71
+ true,
72
+ false,
73
+ ],
74
+ 'HTML 4.01 Frameset' => [
75
+ '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">',
76
+ true,
77
+ false,
78
+ ],
79
+ 'HTML 5' => [
80
+ '<!DOCTYPE html>',
81
+ true,
82
+ true,
83
+ ],
84
+ 'HTML 5 legacy compatible' => [
85
+ '<!DOCTYPE HTML SYSTEM "about:legacy-compat">',
86
+ true,
87
+ true,
88
+ ],
89
+ }.each { |name, (dtd_str, html_p, html5_p)|
90
+ doc = Nokogiri(dtd_str)
91
+ dtd = doc.internal_subset
92
+ assert_instance_of Nokogiri::XML::DTD, dtd, name
93
+ if html_p
94
+ assert_send [dtd, :html_dtd?], name
95
+ else
96
+ assert_not_send [dtd, :html_dtd?], name
97
+ end
98
+ if html5_p
99
+ assert_send [dtd, :html5_dtd?], name
100
+ else
101
+ assert_not_send [dtd, :html5_dtd?], name
102
+ end
103
+ }
104
+ end
105
+
22
106
  def test_content
23
107
  assert_raise NoMethodError do
24
108
  @dtd.content
@@ -233,10 +233,10 @@ EOF
233
233
 
234
234
  test_relative_and_absolute_path :test_reader_entity_reference_without_dtdload do
235
235
  html = File.read xml_document
236
+ reader = Nokogiri::XML::Reader html, path do |cfg|
237
+ cfg.default_xml
238
+ end
236
239
  assert_raises(Nokogiri::XML::SyntaxError) do
237
- reader = Nokogiri::XML::Reader html, path do |cfg|
238
- cfg.default_xml
239
- end
240
240
  reader.each { |n| n }
241
241
  end
242
242
  end
@@ -133,6 +133,12 @@ module Nokogiri
133
133
  node.parse('<baz><</baz>')
134
134
  end
135
135
 
136
+ def test_parse_with_unparented_text_context_node
137
+ doc = XML::Document.new
138
+ elem = XML::Text.new("foo", doc)
139
+ elem.parse("<bar/>")
140
+ end
141
+
136
142
  def test_subclass_dup
137
143
  subclass = Class.new(Nokogiri::XML::Node)
138
144
  node = subclass.new('foo', @xml).dup
@@ -1006,16 +1012,28 @@ EOXML
1006
1012
  <y xmlns:c='http://bazz.com/'>
1007
1013
  <a:div>hello a</a:div>
1008
1014
  <b:div>hello b</b:div>
1009
- <c:div>hello c</c:div>
1010
- <div>hello moon</div>
1015
+ <c:div x="1" b:y="2">hello c</c:div>
1016
+ <div x="1" xmlns="http://ns.example.com/d"/>
1017
+ <div x="1">hello moon</div>
1011
1018
  </y>
1012
1019
  </x>
1013
1020
  EOF
1014
1021
  set = xml.search("//y/*")
1015
1022
  assert_equal "a", set[0].namespace.prefix
1023
+ assert_equal 'http://foo.com/', set[0].namespace.href
1016
1024
  assert_equal "b", set[1].namespace.prefix
1025
+ assert_equal 'http://bar.com/', set[1].namespace.href
1017
1026
  assert_equal "c", set[2].namespace.prefix
1018
- assert_equal nil, set[3].namespace
1027
+ assert_equal 'http://bazz.com/', set[2].namespace.href
1028
+ assert_equal nil, set[3].namespace.prefix # default namespace
1029
+ assert_equal 'http://ns.example.com/d', set[3].namespace.href
1030
+ assert_equal nil, set[4].namespace # no namespace
1031
+
1032
+ assert_equal 'b', set[2].attributes['y'].namespace.prefix
1033
+ assert_equal 'http://bar.com/', set[2].attributes['y'].namespace.href
1034
+ assert_equal nil, set[2].attributes['x'].namespace
1035
+ assert_equal nil, set[3].attributes['x'].namespace
1036
+ assert_equal nil, set[4].attributes['x'].namespace
1019
1037
  end
1020
1038
 
1021
1039
  if Nokogiri.uses_libxml?
@@ -59,6 +59,23 @@ module Nokogiri
59
59
  assert_equal [], node.namespace_definitions.map(&:prefix)
60
60
  end
61
61
 
62
+ def test_append_child_element_with_prefixed_attributes
63
+ doc = Nokogiri::XML "<root/>"
64
+ node = doc.root
65
+
66
+ assert_equal [], node.namespace_definitions.map(&:prefix)
67
+
68
+
69
+ # assert_nothing_raised do
70
+ child_node = Nokogiri::XML::Node.new 'foo', doc
71
+ child_node['xml:lang'] = 'en-GB'
72
+
73
+ node << child_node
74
+ # end
75
+
76
+ assert_equal [], child_node.namespace_definitions.map(&:prefix)
77
+ end
78
+
62
79
  def test_namespace_key?
63
80
  doc = Nokogiri::XML <<-eoxml
64
81
  <root xmlns:tlm='http://tenderlovemaking.com/'>
@@ -14,6 +14,32 @@ module Nokogiri
14
14
  assert_instance_of Nokogiri::XML::Schema, xsd
15
15
  end
16
16
 
17
+ def test_invalid_schema_do_not_raise_exceptions
18
+ xsd = Nokogiri::XML::Schema.new <<EOF
19
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
20
+ <xs:group name="foo1">
21
+ <xs:sequence>
22
+ <xs:element name="bar" type="xs:boolean" />
23
+ </xs:sequence>
24
+ </xs:group>
25
+ <xs:group name="foo2">
26
+ <xs:sequence>
27
+ <xs:element name="bar" type="xs:string" />
28
+ </xs:sequence>
29
+ </xs:group>
30
+ <xs:element name="foo">
31
+ <xs:complexType>
32
+ <xs:choice>
33
+ <xs:group ref="foo1"/>
34
+ <xs:group ref="foo2"/>
35
+ </xs:choice>
36
+ </xs:complexType>
37
+ </xs:element>
38
+ </xs:schema>
39
+ EOF
40
+ assert_instance_of Nokogiri::XML::Schema, xsd
41
+ end
42
+
17
43
  def test_schema_from_document_node
18
44
  doc = Nokogiri::XML(File.open(PO_SCHEMA_FILE))
19
45
  assert doc
@@ -40,6 +40,21 @@ module Nokogiri
40
40
  assert_equal('& <foo> &amp;', node.content)
41
41
  assert_equal('&amp; &lt;foo&gt; &amp;amp;', node.to_xml)
42
42
  end
43
+
44
+ def test_add_child
45
+ node = Text.new('foo', Document.new)
46
+ if Nokogiri.jruby?
47
+ exc = RuntimeError
48
+ else
49
+ exc = ArgumentError
50
+ end
51
+ assert_raises(exc) {
52
+ node.add_child Text.new('bar', Document.new)
53
+ }
54
+ assert_raises(exc) {
55
+ node << Text.new('bar', Document.new)
56
+ }
57
+ end
43
58
  end
44
59
  end
45
60
  end
@@ -132,6 +132,51 @@ module Nokogiri
132
132
  assert_equal(['asdf'] * set.length, @handler.things)
133
133
  end
134
134
 
135
+ def parse_params node
136
+ params={}
137
+ node.xpath('./param').each do |p|
138
+ subparams = parse_params p
139
+ if(subparams.length > 0)
140
+ if(not params.has_key? p.attributes['name'].value)
141
+ params[p.attributes['name'].value] = subparams
142
+ else
143
+ if(params[p.attributes['name'].value].is_a? Array)
144
+ params[p.attributes['name'].value] << subparams
145
+ else
146
+ value = params[p.attributes['name'].value]
147
+ params[p.attributes['name'].value] = [value,subparams]
148
+ end
149
+ end
150
+ else
151
+ params[p.attributes['name'].value]=p.text
152
+ end
153
+ end
154
+ params
155
+ end
156
+
157
+ # issue #741 (xpath() around 10x slower in JRuby)
158
+ def test_slow_jruby_xpath
159
+ doc = Nokogiri::XML(File.open(XPATH_FILE))
160
+ start = Time.now
161
+
162
+ doc.xpath('.//category').each do |c|
163
+ c.xpath('programformats/programformat').each do |p|
164
+ p.xpath('./modules/module').each do |m|
165
+ parse_params m
166
+ end
167
+ end
168
+ end
169
+ stop = Time.now
170
+ elapsed_time = stop - start
171
+ time_limit =
172
+ if ENV['TRAVIS'] && ENV['CI']
173
+ 20 # Travis CI box slowness
174
+ else
175
+ 10
176
+ end
177
+ assert_send [elapsed_time, :<, time_limit], "XPath is taking too long"
178
+ end
179
+
135
180
  def test_custom_xpath_function_returns_string
136
181
  if Nokogiri.uses_libxml?
137
182
  result = @xml.xpath('thing("asdf")', @handler)
@@ -290,6 +335,48 @@ END
290
335
  onix = xml_doc.children.first
291
336
  assert_equal 'a', onix.at_xpath('xmlns:Product').at_xpath('xmlns:RecordReference').text
292
337
  end
338
+
339
+ def test_xpath_after_attribute_change
340
+ xml_string = %q{<?xml version="1.0" encoding="UTF-8"?>
341
+ <mods version="3.0" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-0.xsd" xmlns="http://www.loc.gov/mods/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
342
+ <titleInfo>
343
+ <nonSort>THE</nonSort>
344
+ <title xml:lang="eng">ARTICLE TITLE HYDRANGEA ARTICLE 1</title>
345
+ <subTitle>SUBTITLE</subTitle>
346
+ </titleInfo>
347
+ <titleInfo lang="finnish">
348
+ <title>Artikkelin otsikko Hydrangea artiklan 1</title>
349
+ </titleInfo>
350
+ </mods>}
351
+
352
+ xml_doc = Nokogiri::XML(xml_string)
353
+ ns_hash = {'mods'=>'http://www.loc.gov/mods/v3'}
354
+ node = xml_doc.at_xpath('//mods:titleInfo[1]',ns_hash)
355
+ node['lang'] = 'english'
356
+ assert_equal 1, xml_doc.xpath('//mods:titleInfo[1]/@lang',ns_hash).length
357
+ assert_equal 'english', xml_doc.xpath('//mods:titleInfo[1]/@lang',ns_hash).first.value
358
+ end
359
+
360
+ def test_xpath_after_element_removal
361
+ xml_string = %q{<?xml version="1.0" encoding="UTF-8"?>
362
+ <mods version="3.0" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-0.xsd" xmlns="http://www.loc.gov/mods/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
363
+ <titleInfo>
364
+ <nonSort>THE</nonSort>
365
+ <title xml:lang="eng">ARTICLE TITLE HYDRANGEA ARTICLE 1</title>
366
+ <subTitle>SUBTITLE</subTitle>
367
+ </titleInfo>
368
+ <titleInfo lang="finnish">
369
+ <title>Artikkelin otsikko Hydrangea artiklan 1</title>
370
+ </titleInfo>
371
+ </mods>}
372
+
373
+ xml_doc = Nokogiri::XML(xml_string)
374
+ ns_hash = {'mods'=>'http://www.loc.gov/mods/v3'}
375
+ node = xml_doc.at_xpath('//mods:titleInfo[1]',ns_hash)
376
+ node.remove
377
+ assert_equal 1, xml_doc.xpath('//mods:titleInfo',ns_hash).length
378
+ assert_equal 'finnish', xml_doc.xpath('//mods:titleInfo[1]/@lang',ns_hash).first.value
379
+ end
293
380
  end
294
381
  end
295
382
  end
data/test_all CHANGED
@@ -10,7 +10,7 @@
10
10
  # (e.g., 1.9.3's glob_helper). ["rake test:valgrind:suppression"]
11
11
  #
12
12
 
13
- RUBIES="ruby-1.9.3-p327 jruby-1.7.3 jruby-1.6.5.1 jruby-1.6.7.2 ruby-1.9.2-p320"
13
+ RUBIES="ruby-1.9.3 ruby-1.9.2 ruby-2.0 ruby-2.1 jruby-1.7"
14
14
  TEST_LOG=test.log
15
15
  VALGRIND_LOG=valgrind.log
16
16
 
@@ -34,7 +34,7 @@ function rvm_use {
34
34
 
35
35
  function generate_parser_and_tokenizer {
36
36
  old_ruby=$current_ruby
37
- rvm_use ruby-1.9.3-p327
37
+ rvm_use ruby-1.9.3
38
38
  bundle exec rake generate 2>&1 > /dev/null
39
39
  rvm_use $old_ruby
40
40
  }
@@ -51,7 +51,7 @@ function compile {
51
51
 
52
52
  for ruby in $RUBIES ; do
53
53
  rvm_use ${ruby}
54
- if ! which bundle ; then
54
+ if ! [[ $(bundle -v) =~ "1.6." ]] ; then
55
55
  gem install bundler
56
56
  fi
57
57
  bundle install --quiet --local || bundle install