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
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2008 - 2016:
3
+ Copyright (c) 2008 - 2017:
4
4
 
5
5
  * [Aaron Patterson](http://tenderlovemaking.com)
6
6
  * [Mike Dalessio](http://mike.daless.io)
@@ -7,7 +7,9 @@ CHANGELOG.md
7
7
  CONTRIBUTING.md
8
8
  C_CODING_STYLE.rdoc
9
9
  Gemfile
10
- LICENSE.txt
10
+ Gemfile-libxml-ruby
11
+ LICENSE-DEPENDENCIES.md
12
+ LICENSE.md
11
13
  Manifest.txt
12
14
  README.md
13
15
  ROADMAP.md
@@ -54,7 +56,6 @@ ext/java/nokogiri/internals/ClosedStreamException.java
54
56
  ext/java/nokogiri/internals/HtmlDomParserContext.java
55
57
  ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java
56
58
  ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java
57
- ext/java/nokogiri/internals/NokogiriDocumentCache.java
58
59
  ext/java/nokogiri/internals/NokogiriDomParser.java
59
60
  ext/java/nokogiri/internals/NokogiriEncodingReaderWrapper.java
60
61
  ext/java/nokogiri/internals/NokogiriEntityResolver.java
@@ -75,10 +76,10 @@ ext/java/nokogiri/internals/ReaderNode.java
75
76
  ext/java/nokogiri/internals/SaveContextVisitor.java
76
77
  ext/java/nokogiri/internals/SchemaErrorHandler.java
77
78
  ext/java/nokogiri/internals/UncloseableInputStream.java
79
+ ext/java/nokogiri/internals/XalanDTMManagerPatch.java
78
80
  ext/java/nokogiri/internals/XmlDeclHandler.java
79
81
  ext/java/nokogiri/internals/XmlDomParserContext.java
80
82
  ext/java/nokogiri/internals/XmlSaxParser.java
81
- ext/java/nokogiri/internals/XsltExtensionFunction.java
82
83
  ext/java/nokogiri/internals/c14n/AttrCompare.java
83
84
  ext/java/nokogiri/internals/c14n/C14nHelper.java
84
85
  ext/java/nokogiri/internals/c14n/CanonicalFilter.java
@@ -106,6 +107,7 @@ ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java
106
107
  ext/java/nokogiri/internals/c14n/NodeFilter.java
107
108
  ext/java/nokogiri/internals/c14n/UtfHelpper.java
108
109
  ext/java/nokogiri/internals/c14n/XMLUtils.java
110
+ ext/java/org/apache/xml/dtm/ref/dom2dtm/DOM2DTMExt.java
109
111
  ext/nokogiri/depend
110
112
  ext/nokogiri/extconf.rb
111
113
  ext/nokogiri/html_document.c
@@ -253,10 +255,6 @@ patches/libxslt/0001-Fix-heap-overread-in-xsltFormatNumberConversion.patch
253
255
  patches/libxslt/0002-Check-for-integer-overflow-in-xsltAddTextString.patch
254
256
  patches/sort-patches-by-date
255
257
  suppressions/README.txt
256
- suppressions/nokogiri_ree-1.8.7.358.supp
257
- suppressions/nokogiri_ruby-1.8.7.370.supp
258
- suppressions/nokogiri_ruby-1.9.2.320.supp
259
- suppressions/nokogiri_ruby-1.9.3.327.supp
260
258
  tasks/test.rb
261
259
  test/css/test_nthiness.rb
262
260
  test/css/test_parser.rb
@@ -366,4 +364,3 @@ test/xml/test_xinclude.rb
366
364
  test/xml/test_xpath.rb
367
365
  test/xslt/test_custom_functions.rb
368
366
  test/xslt/test_exception_handling.rb
369
- test_all
data/README.md CHANGED
@@ -10,10 +10,13 @@
10
10
 
11
11
  ## Status
12
12
 
13
- [![Travis Build Status](https://travis-ci.org/sparklemotion/nokogiri.svg?branch=master)](https://travis-ci.org/sparklemotion/nokogiri)
14
- [![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/github/sparklemotion/nokogiri?branch=master&svg=true)](https://ci.appveyor.com/project/flavorjones/nokogiri?branch=master)
15
- [![Code Climate](https://codeclimate.com/github/sparklemotion/nokogiri.svg)](https://codeclimate.com/github/sparklemotion/nokogiri)
16
- [![Version Eye](https://www.versioneye.com/ruby/nokogiri/badge.png)](https://www.versioneye.com/ruby/nokogiri)
13
+ |System|Status|
14
+ |--|--|
15
+ | Concourse | [![Concourse CI](https://ci.nokogiri.org/api/v1/teams/nokogiri-core/pipelines/nokogiri/jobs/ruby-2.4-system/badge)](https://ci.nokogiri.org/teams/nokogiri-core/pipelines/nokogiri?groups=master) |
16
+ | Travis | [![Travis Build Status](https://travis-ci.org/sparklemotion/nokogiri.svg?branch=master)](https://travis-ci.org/sparklemotion/nokogiri) |
17
+ | Appveyor | [![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/github/sparklemotion/nokogiri?branch=master&svg=true)](https://ci.appveyor.com/project/flavorjones/nokogiri?branch=master) |
18
+ | Code Climate | [![Code Climate](https://codeclimate.com/github/sparklemotion/nokogiri.svg)](https://codeclimate.com/github/sparklemotion/nokogiri) |
19
+ | Version Eye | [![Version Eye](https://www.versioneye.com/ruby/nokogiri/badge.png)](https://www.versioneye.com/ruby/nokogiri) |
17
20
 
18
21
 
19
22
  ## Description
@@ -167,4 +170,4 @@ explicitly setting the encoding to EUC-JP on the parser:
167
170
 
168
171
  ## License
169
172
 
170
- MIT. See the `LICENSE.txt` file.
173
+ MIT. See the `LICENSE.md` file.
data/Rakefile CHANGED
@@ -125,25 +125,29 @@ HOE = Hoe.spec 'nokogiri' do
125
125
 
126
126
  unless java?
127
127
  self.extra_deps += [
128
- ["mini_portile2", "~> 2.1.0"], # keep version in sync with extconf.rb
128
+ ["mini_portile2", "~> 2.2.0"], # keep version in sync with extconf.rb
129
129
  ]
130
130
  end
131
131
 
132
132
  self.extra_dev_deps += [
133
133
  ["hoe-bundler", "~> 1.2.0"],
134
- ["hoe-debugging", "~> 1.2.1"],
134
+ ["hoe-debugging", "~> 1.3.0"],
135
135
  ["hoe-gemspec", "~> 1.0.0"],
136
136
  ["hoe-git", "~> 1.6.0"],
137
137
  ["minitest", "~> 5.8.4"],
138
- ["rake", "~> 10.5.0"],
139
- ["rake-compiler", "~> 0.9.2"],
140
- ["rake-compiler-dock", "~> 0.5.1"],
138
+ ["rake", "~> 12.0"],
139
+ ["rake-compiler", "~> 1.0.3"],
140
+ ["rake-compiler-dock", "~> 0.6.0"],
141
141
  ["racc", "~> 1.4.14"],
142
- ["rexical", "~> 1.0.5"]
142
+ ["rexical", "~> 1.0.5"],
143
+ ["concourse", "~> 0.11"],
143
144
  ]
144
145
 
145
146
  if java?
146
- self.spec_extras = { :platform => 'java' }
147
+ self.spec_extras = {
148
+ :platform => 'java',
149
+ :required_ruby_version => '>= 1.9.3' # JRuby >= 1.7
150
+ }
147
151
  else
148
152
  self.spec_extras = {
149
153
  :extensions => ["ext/nokogiri/extconf.rb"],
@@ -230,11 +234,6 @@ else
230
234
  ext.cross_compiling do |spec|
231
235
  libs = dependencies.map { |name, dep| "#{name}-#{dep["version"]}" }.join(', ')
232
236
 
233
- spec.required_ruby_version = [
234
- '>= 2.1.0',
235
- "< #{CROSS_RUBIES.max_by(&:ver).minor_ver.succ}"
236
- ]
237
-
238
237
  spec.post_install_message = <<-EOS
239
238
  Nokogiri is built with the packaged libraries: #{libs}.
240
239
  EOS
@@ -259,7 +258,7 @@ task 'bundler:gemfile' do
259
258
  old_gemfile_task.invoke if old_gemfile_task
260
259
 
261
260
  lines = File.open('Gemfile', 'r') { |f| f.readlines }.map do |line|
262
- line =~ /racc|rexical/ ? "#{line.strip}, :platform => :ruby" : line
261
+ line =~ /racc|rexical/ ? "#{line.strip}, :platform => [:ruby, :mingw, :x64_mingw]" : line
263
262
  end
264
263
  File.open('Gemfile', 'w') { |f| lines.each { |line| f.puts line } }
265
264
  end
@@ -314,23 +313,8 @@ if Hoe.plugins.include?(:debugging)
314
313
  end
315
314
  end
316
315
 
317
- task "test:libxml-ruby" do
318
- ENV['TEST_NOKOGIRI_WITH_LIBXML_RUBY'] = "1"
319
- warn "#{__FILE__}:#{__LINE__}: --- running tests with libxml-ruby loaded ---"
320
- Rake::Task[:test].execute
321
- ENV['TEST_NOKOGIRI_WITH_LIBXML_RUBY'] = nil
322
- end
323
-
324
- Rake::Task["test:libxml-ruby"].prerequisites << :compile
325
-
326
- task "test:valgrind:libxml-ruby" do
327
- ENV['TEST_NOKOGIRI_WITH_LIBXML_RUBY'] = "1"
328
- warn "#{__FILE__}:#{__LINE__}: --- running tests with libxml-ruby loaded ---"
329
- Rake::Task["test:valgrind"].execute
330
- ENV['TEST_NOKOGIRI_WITH_LIBXML_RUBY'] = nil
331
- end
332
-
333
- Rake::Task["test:valgrind:libxml-ruby"].prerequisites << :compile
316
+ require 'concourse'
317
+ Concourse.new("nokogiri").create_tasks!
334
318
 
335
319
  # ----------------------------------------
336
320
 
@@ -352,7 +336,7 @@ end
352
336
  task :cross do
353
337
  rake_compiler_config_path = File.expand_path("~/.rake-compiler/config.yml")
354
338
  unless File.exists? rake_compiler_config_path
355
- raise "rake-compiler has not installed any cross rubies. Try using rake-compiler-dev-box for building binary windows gems.'"
339
+ raise "rake-compiler has not installed any cross rubies. Use rake-compiler-dock or 'rake gem:windows' for building binary windows gems."
356
340
  end
357
341
 
358
342
  CROSS_RUBIES.each do |cross_ruby|
@@ -13,6 +13,8 @@ test_script:
13
13
 
14
14
  environment:
15
15
  matrix:
16
+ - ruby_version: "23"
17
+ - ruby_version: "23-x64"
16
18
  - ruby_version: "22"
17
19
  - ruby_version: "22-x64"
18
20
  - ruby_version: "21"
@@ -1,6 +1,6 @@
1
1
  libxml2:
2
2
  version: "2.9.4"
3
- md5: "ae249165c173b1ff386ee8ad676815f5" # manually confirmed via `gpg --verify`
3
+ sha256: "ffb911191e509b966deb55de705387f14156e1a56b21824357cdf0053233633c" # manually confirmed via `gpg --verify`
4
4
  # gpg: Signature made Mon 23 May 2016 04:02:13 AM EDT using DSA key ID DE95BC1F
5
5
  # gpg: Good signature from "Daniel Veillard (Red Hat work email) <veillard@redhat.com>"
6
6
  # gpg: aka "Daniel Veillard <Daniel.Veillard@w3.org>"
@@ -10,7 +10,7 @@ libxml2:
10
10
 
11
11
  libxslt:
12
12
  version: "1.1.29"
13
- md5: "a129d3c44c022de3b9dcf6d6f288d72e"
13
+ sha256: "b5976e3857837e7617b29f2249ebb5eeac34e249208d31f1fbf7a6ba7a4090ce"
14
14
  # gpg: Signature made Mon 23 May 2016 09:58:52 PM EDT using DSA key ID DE95BC1F
15
15
  # gpg: Good signature from "Daniel Veillard (Red Hat work email) <veillard@redhat.com>"
16
16
  # gpg: aka "Daniel Veillard <Daniel.Veillard@w3.org>"
@@ -20,10 +20,15 @@ libxslt:
20
20
 
21
21
  zlib:
22
22
  version: "1.2.11"
23
- md5: "1c9f62f0778697a09d36121ead88e08e"
23
+ sha256: "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1"
24
+ # SHA-256 hash provided on http://zlib.net/
24
25
 
25
26
  libiconv:
26
- version: "1.14"
27
- md5: "e34509b1623cec449dfeb73d7ce9c6c6"
28
- # gpg: Signature made Sun 07 Aug 2011 01:58:18 PM EDT using DSA key ID F059B1D1
29
- # gpg: BAD signature from "Bruno Haible (Open Source Development) <bruno@clisp.org>"
27
+ version: "1.15"
28
+ sha256: "ccf536620a45458d26ba83887a983b96827001e92a13847b45e4925cc8913178"
29
+ # gpg: Signature made Fri Feb 3 00:38:12 2017 CET
30
+ # gpg: using RSA key 4F494A942E4616C2
31
+ # gpg: Good signature from "Bruno Haible (Open Source Development) <bruno@clisp.org>" [unknown]
32
+ # gpg: WARNING: This key is not certified with a trusted signature!
33
+ # gpg: There is no indication that the signature belongs to the owner.
34
+ # Primary key fingerprint: 68D9 4D8A AEEA D48A E7DC 5B90 4F49 4A94 2E46 16C2
@@ -72,13 +72,13 @@ public class HtmlDocument extends XmlDocument {
72
72
  @JRubyMethod(name="new", meta = true, rest = true, required=0)
73
73
  public static IRubyObject rbNew(ThreadContext context, IRubyObject klazz,
74
74
  IRubyObject[] args) {
75
- HtmlDocument htmlDocument = null;
75
+ HtmlDocument htmlDocument;
76
76
  try {
77
77
  Document docNode = createNewDocument();
78
78
  htmlDocument = (HtmlDocument) NokogiriService.HTML_DOCUMENT_ALLOCATOR.allocate(context.getRuntime(), (RubyClass) klazz);
79
79
  htmlDocument.setDocumentNode(context, docNode);
80
80
  } catch (Exception ex) {
81
- throw context.getRuntime().newRuntimeError("couldn't create document: "+ex.toString());
81
+ throw context.getRuntime().newRuntimeError("couldn't create document: " + ex);
82
82
  }
83
83
 
84
84
  RuntimeHelpers.invoke(context, htmlDocument, "initialize", args);
@@ -38,6 +38,7 @@ import java.io.ByteArrayInputStream;
38
38
  import java.io.InputStream;
39
39
  import java.nio.charset.Charset;
40
40
  import java.nio.charset.IllegalCharsetNameException;
41
+ import java.nio.charset.UnsupportedCharsetException;
41
42
  import java.util.EnumSet;
42
43
  import java.util.regex.Matcher;
43
44
  import java.util.regex.Pattern;
@@ -46,10 +47,7 @@ import nokogiri.internals.NokogiriHandler;
46
47
 
47
48
  import org.apache.xerces.parsers.AbstractSAXParser;
48
49
  import org.cyberneko.html.parsers.SAXParser;
49
- import org.jruby.Ruby;
50
- import org.jruby.RubyClass;
51
- import org.jruby.RubyFixnum;
52
- import org.jruby.RubyString;
50
+ import org.jruby.*;
53
51
  import org.jruby.anno.JRubyClass;
54
52
  import org.jruby.anno.JRubyMethod;
55
53
  import org.jruby.runtime.ThreadContext;
@@ -104,7 +102,7 @@ public class HtmlSaxParserContext extends XmlSaxParserContext {
104
102
  return ctx;
105
103
  }
106
104
 
107
- public static enum EncodingType {
105
+ public enum EncodingType {
108
106
  NONE(0, "NONE"),
109
107
  UTF_8(1, "UTF-8"),
110
108
  UTF16LE(2, "UTF16LE"),
@@ -131,6 +129,7 @@ public class HtmlSaxParserContext extends XmlSaxParserContext {
131
129
 
132
130
  private final int value;
133
131
  private final String name;
132
+
134
133
  EncodingType(int value, String name) {
135
134
  this.value = value;
136
135
  this.name = name;
@@ -145,9 +144,8 @@ public class HtmlSaxParserContext extends XmlSaxParserContext {
145
144
  }
146
145
  }
147
146
 
148
- private static String findName(int value) {
149
- EnumSet<EncodingType> set = EnumSet.allOf(EncodingType.class);
150
- for (EncodingType type : set) {
147
+ private static String findName(final int value) {
148
+ for (EncodingType type : EncodingType.values()) {
151
149
  if (type.getValue() == value) return type.toString();
152
150
  }
153
151
  return null;
@@ -157,30 +155,31 @@ public class HtmlSaxParserContext extends XmlSaxParserContext {
157
155
  String rubyEncoding = null;
158
156
  if (encoding instanceof RubyString) {
159
157
  rubyEncoding = rubyStringToString(encoding);
160
- } else if (encoding instanceof RubyFixnum) {
161
- int value = (Integer)encoding.toJava(Integer.class);
158
+ }
159
+ else if (encoding instanceof RubyFixnum) {
160
+ int value = RubyFixnum.fix2int((RubyFixnum) encoding);
162
161
  rubyEncoding = findName(value);
163
162
  }
164
163
  if (rubyEncoding == null) return null;
165
164
  try {
166
- Charset charset = Charset.forName(rubyEncoding);
167
- return charset.displayName();
168
- } catch (IllegalCharsetNameException e) {
169
- throw context.getRuntime().newEncodingCompatibilityError(
170
- rubyEncoding + "is not supported in Java.");
171
- } catch (IllegalArgumentException e) {
172
- throw context.getRuntime().newInvalidEncoding(
173
- "encoding should not be nil");
165
+ return Charset.forName(rubyEncoding).displayName();
166
+ }
167
+ catch (UnsupportedCharsetException e) {
168
+ throw context.getRuntime().newEncodingCompatibilityError(rubyEncoding + "is not supported");
169
+ }
170
+ catch (IllegalCharsetNameException e) {
171
+ throw context.getRuntime().newInvalidEncoding(e.getMessage());
174
172
  }
175
173
  }
176
-
174
+
175
+ private static final Pattern CHARSET_PATTERN = Pattern.compile("charset(()|\\s)=(()|\\s)([a-z]|-|_|\\d)+");
176
+
177
177
  private static String applyEncoding(String input, String enc) {
178
178
  String str = input.toLowerCase();
179
179
  int start_pos = 0;
180
180
  int end_pos = 0;
181
181
  if (input.contains("meta") && input.contains("charset")) {
182
- Pattern p = Pattern.compile("charset(()|\\s)=(()|\\s)([a-z]|-|_|\\d)+");
183
- Matcher m = p.matcher(str);
182
+ Matcher m = CHARSET_PATTERN.matcher(str);
184
183
  while (m.find()) {
185
184
  start_pos = m.start();
186
185
  end_pos = m.end();
@@ -50,6 +50,7 @@ import java.util.concurrent.ThreadFactory;
50
50
 
51
51
  import nokogiri.internals.ClosedStreamException;
52
52
  import nokogiri.internals.NokogiriBlockingQueueInputStream;
53
+ import nokogiri.internals.NokogiriHelpers;
53
54
  import nokogiri.internals.ParserContext;
54
55
 
55
56
  import org.jruby.Ruby;
@@ -133,18 +134,13 @@ public class HtmlSaxPushParser extends RubyObject {
133
134
  } catch (IOException e) {
134
135
  throw context.getRuntime().newRuntimeError(e.getMessage());
135
136
  }
136
- byte[] data = null;
137
- if (chunk instanceof RubyString || chunk.respondsTo("to_str")) {
138
- data = chunk.convertToString().getBytes();
139
- } else {
137
+ final ByteArrayInputStream data = NokogiriHelpers.stringBytesToStream(chunk);
138
+ if (data == null) {
140
139
  terminateTask(context);
141
- XmlSyntaxError xmlSyntaxError =
142
- (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::HTML::SyntaxError"));
143
- throw new RaiseException(xmlSyntaxError);
140
+ throw new RaiseException(XmlSyntaxError.createHTMLSyntaxError(context.runtime)); // Nokogiri::HTML::SyntaxError
144
141
  }
145
142
 
146
- int errorCount0 = parserTask.getErrorCount();;
147
-
143
+ int errorCount0 = parserTask.getErrorCount();
148
144
 
149
145
  if (isLast.isTrue()) {
150
146
  IRubyObject document = invoke(context, this, "document");
@@ -152,7 +148,7 @@ public class HtmlSaxPushParser extends RubyObject {
152
148
  terminateTask(context);
153
149
  } else {
154
150
  try {
155
- Future<Void> task = stream.addChunk(new ByteArrayInputStream(data));
151
+ Future<Void> task = stream.addChunk(data);
156
152
  task.get();
157
153
  } catch (ClosedStreamException ex) {
158
154
  // this means the stream is closed, ignore this exception
@@ -72,8 +72,6 @@ public class NokogiriService implements BasicLibraryService {
72
72
  MonkeyPatchHTMLElements.patchIt();
73
73
  }
74
74
 
75
- public static final String nokogiriClassCacheGvarName = "$NOKOGIRI_CLASS_CACHE";
76
-
77
75
  public boolean basicLoad(Ruby ruby) {
78
76
  init(ruby);
79
77
  return true;
@@ -84,7 +82,7 @@ public class NokogiriService implements BasicLibraryService {
84
82
  }
85
83
 
86
84
  private static Map<String, RubyClass> populateNokogiriClassCahce(Ruby ruby) {
87
- Map<String, RubyClass> nokogiriClassCache = Collections.synchronizedMap(new HashMap<String, RubyClass>());
85
+ Map<String, RubyClass> nokogiriClassCache = new HashMap<String, RubyClass>();
88
86
  nokogiriClassCache.put("Nokogiri::EncodingHandler", (RubyClass)ruby.getClassFromPath("Nokogiri::EncodingHandler"));
89
87
  nokogiriClassCache.put("Nokogiri::HTML::Document", (RubyClass)ruby.getClassFromPath("Nokogiri::HTML::Document"));
90
88
  nokogiriClassCache.put("Nokogiri::HTML::ElementDescription", (RubyClass)ruby.getClassFromPath("Nokogiri::HTML::ElementDescription"));
@@ -111,8 +109,7 @@ public class NokogiriService implements BasicLibraryService {
111
109
  nokogiriClassCache.put("Nokogiri::XML::XPathContext", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::XPathContext"));
112
110
  nokogiriClassCache.put("Nokogiri::XML::AttributeDecl", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::AttributeDecl"));
113
111
  nokogiriClassCache.put("Nokogiri::XML::SAX::ParserContext", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::SAX::ParserContext"));
114
- nokogiriClassCache.put("StringIO", (RubyClass)ruby.getClassFromPath("StringIO"));
115
- return nokogiriClassCache;
112
+ return Collections.unmodifiableMap(nokogiriClassCache);
116
113
  }
117
114
 
118
115
  private void init(Ruby ruby) {
@@ -139,7 +136,7 @@ public class NokogiriService implements BasicLibraryService {
139
136
  nokogiri.defineConstant("NEKO_VERSION", ruby.newString(org.cyberneko.html.Version.getVersion()));
140
137
  }
141
138
 
142
- private void createNokogiriModule(Ruby ruby, RubyModule nokogiri) {;
139
+ private void createNokogiriModule(Ruby ruby, RubyModule nokogiri) {
143
140
  RubyClass encHandler = nokogiri.defineClassUnder("EncodingHandler", ruby.getObject(), ENCODING_HANDLER_ALLOCATOR);
144
141
  encHandler.defineAnnotatedMethods(EncodingHandler.class);
145
142
  }
@@ -471,9 +468,7 @@ public class NokogiriService implements BasicLibraryService {
471
468
  clone.setMetaClass(klazz);
472
469
  return clone;
473
470
  } catch (CloneNotSupportedException e) {
474
- xmlNodeSet = new XmlNodeSet(runtime, klazz);
475
- xmlNodeSet.setNodes(RubyArray.newEmptyArray(runtime));
476
- return xmlNodeSet;
471
+ return new XmlNodeSet(runtime, klazz);
477
472
  }
478
473
  }
479
474
  };
@@ -553,13 +548,13 @@ public class NokogiriService implements BasicLibraryService {
553
548
  }
554
549
  };
555
550
 
556
- private static ObjectAllocator XML_SAXPUSHPARSER_ALLOCATOR = new ObjectAllocator() {
551
+ private static final ObjectAllocator XML_SAXPUSHPARSER_ALLOCATOR = new ObjectAllocator() {
557
552
  public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
558
553
  return new XmlSaxPushParser(runtime, klazz);
559
554
  }
560
555
  };
561
-
562
- private static ObjectAllocator HTML_SAXPUSHPARSER_ALLOCATOR = new ObjectAllocator() {
556
+
557
+ private static final ObjectAllocator HTML_SAXPUSHPARSER_ALLOCATOR = new ObjectAllocator() {
563
558
  public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
564
559
  return new HtmlSaxPushParser(runtime, klazz);
565
560
  }
@@ -580,16 +575,8 @@ public class NokogiriService implements BasicLibraryService {
580
575
  };
581
576
 
582
577
  public static final ObjectAllocator XML_SYNTAXERROR_ALLOCATOR = new ObjectAllocator() {
583
- private XmlSyntaxError xmlSyntaxError = null;
584
578
  public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
585
- if (xmlSyntaxError == null) xmlSyntaxError = new XmlSyntaxError(runtime, klazz);
586
- try {
587
- XmlSyntaxError clone = (XmlSyntaxError) xmlSyntaxError.clone();
588
- clone.setMetaClass(klazz);
589
- return clone;
590
- } catch (CloneNotSupportedException e) {
591
- return new XmlSyntaxError(runtime, klazz);
592
- }
579
+ return new XmlSyntaxError(runtime, klazz);
593
580
  }
594
581
  };
595
582
 
@@ -607,17 +594,9 @@ public class NokogiriService implements BasicLibraryService {
607
594
  }
608
595
  };
609
596
 
610
- public static ObjectAllocator XML_XPATHCONTEXT_ALLOCATOR = new ObjectAllocator() {
611
- private XmlXpathContext xmlXpathContext = null;
597
+ public static final ObjectAllocator XML_XPATHCONTEXT_ALLOCATOR = new ObjectAllocator() {
612
598
  public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
613
- if (xmlXpathContext == null) xmlXpathContext = new XmlXpathContext(runtime, klazz);
614
- try {
615
- XmlXpathContext clone = (XmlXpathContext) xmlXpathContext.clone();
616
- clone.setMetaClass(klazz);
617
- return clone;
618
- } catch (CloneNotSupportedException e) {
619
- return new XmlXpathContext(runtime, klazz);
620
- }
599
+ return new XmlXpathContext(runtime, klazz);
621
600
  }
622
601
  };
623
602