nokogiri 1.12.2-java → 1.13.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.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/README.md +9 -7
- data/bin/nokogiri +63 -50
- data/dependencies.yml +5 -6
- data/ext/java/nokogiri/Html4SaxPushParser.java +14 -19
- data/ext/java/nokogiri/XmlDocumentFragment.java +4 -15
- data/ext/java/nokogiri/XmlNamespace.java +0 -8
- data/ext/java/nokogiri/XmlNode.java +32 -16
- data/ext/java/nokogiri/XmlNodeSet.java +0 -4
- data/ext/java/nokogiri/XmlReader.java +12 -0
- data/ext/java/nokogiri/XmlSaxParserContext.java +31 -93
- data/ext/java/nokogiri/XmlSaxPushParser.java +17 -25
- data/ext/java/nokogiri/XmlSchema.java +1 -1
- data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +1 -1
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +29 -8
- data/ext/java/nokogiri/internals/NokogiriHandler.java +6 -24
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +9 -8
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +10 -9
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +7 -6
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +2 -0
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +16 -25
- data/ext/nokogiri/extconf.rb +51 -35
- data/ext/nokogiri/gumbo.c +11 -11
- data/ext/nokogiri/html4_element_description.c +1 -1
- data/ext/nokogiri/html4_sax_parser_context.c +2 -1
- data/ext/nokogiri/nokogiri.c +1 -1
- data/ext/nokogiri/xml_document.c +36 -36
- data/ext/nokogiri/xml_document_fragment.c +0 -2
- data/ext/nokogiri/xml_dtd.c +2 -2
- data/ext/nokogiri/xml_encoding_handler.c +25 -11
- data/ext/nokogiri/xml_namespace.c +2 -2
- data/ext/nokogiri/xml_node.c +647 -335
- data/ext/nokogiri/xml_reader.c +37 -11
- data/ext/nokogiri/xml_xpath_context.c +72 -49
- data/lib/nokogiri/class_resolver.rb +67 -0
- data/lib/nokogiri/css/node.rb +9 -8
- data/lib/nokogiri/css/parser.rb +11 -3
- data/lib/nokogiri/css/parser.y +10 -2
- data/lib/nokogiri/css/parser_extras.rb +20 -20
- data/lib/nokogiri/css/syntax_error.rb +1 -0
- data/lib/nokogiri/css/tokenizer.rb +2 -1
- data/lib/nokogiri/css/tokenizer.rex +2 -1
- data/lib/nokogiri/css/xpath_visitor.rb +174 -75
- data/lib/nokogiri/css.rb +38 -6
- data/lib/nokogiri/decorators/slop.rb +8 -7
- data/lib/nokogiri/extension.rb +1 -1
- data/lib/nokogiri/gumbo.rb +1 -0
- data/lib/nokogiri/html.rb +16 -10
- data/lib/nokogiri/html4/builder.rb +1 -0
- data/lib/nokogiri/html4/document.rb +84 -75
- data/lib/nokogiri/html4/document_fragment.rb +11 -7
- data/lib/nokogiri/html4/element_description.rb +1 -0
- data/lib/nokogiri/html4/element_description_defaults.rb +426 -520
- data/lib/nokogiri/html4/entity_lookup.rb +2 -1
- data/lib/nokogiri/html4/sax/parser.rb +2 -1
- data/lib/nokogiri/html4/sax/parser_context.rb +1 -0
- data/lib/nokogiri/html4/sax/push_parser.rb +7 -7
- data/lib/nokogiri/html4.rb +11 -5
- data/lib/nokogiri/html5/document.rb +24 -10
- data/lib/nokogiri/html5/document_fragment.rb +5 -2
- data/lib/nokogiri/html5/node.rb +6 -3
- data/lib/nokogiri/html5.rb +68 -64
- data/lib/nokogiri/jruby/dependencies.rb +10 -9
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/syntax_error.rb +1 -0
- data/lib/nokogiri/version/constant.rb +2 -1
- data/lib/nokogiri/version/info.rb +19 -13
- data/lib/nokogiri/version.rb +1 -0
- data/lib/nokogiri/xml/attr.rb +5 -3
- data/lib/nokogiri/xml/attribute_decl.rb +2 -1
- data/lib/nokogiri/xml/builder.rb +69 -31
- data/lib/nokogiri/xml/cdata.rb +2 -1
- data/lib/nokogiri/xml/character_data.rb +1 -0
- data/lib/nokogiri/xml/document.rb +178 -96
- data/lib/nokogiri/xml/document_fragment.rb +41 -38
- data/lib/nokogiri/xml/dtd.rb +3 -2
- data/lib/nokogiri/xml/element_content.rb +1 -0
- data/lib/nokogiri/xml/element_decl.rb +2 -1
- data/lib/nokogiri/xml/entity_decl.rb +3 -2
- data/lib/nokogiri/xml/entity_reference.rb +1 -0
- data/lib/nokogiri/xml/namespace.rb +2 -0
- data/lib/nokogiri/xml/node/save_options.rb +7 -4
- data/lib/nokogiri/xml/node.rb +512 -348
- data/lib/nokogiri/xml/node_set.rb +46 -54
- data/lib/nokogiri/xml/notation.rb +12 -0
- data/lib/nokogiri/xml/parse_options.rb +11 -7
- data/lib/nokogiri/xml/pp/character_data.rb +8 -6
- data/lib/nokogiri/xml/pp/node.rb +24 -26
- data/lib/nokogiri/xml/pp.rb +1 -0
- data/lib/nokogiri/xml/processing_instruction.rb +2 -1
- data/lib/nokogiri/xml/reader.rb +17 -19
- data/lib/nokogiri/xml/relax_ng.rb +1 -0
- data/lib/nokogiri/xml/sax/document.rb +20 -19
- data/lib/nokogiri/xml/sax/parser.rb +36 -34
- data/lib/nokogiri/xml/sax/parser_context.rb +7 -3
- data/lib/nokogiri/xml/sax/push_parser.rb +5 -5
- data/lib/nokogiri/xml/sax.rb +1 -0
- data/lib/nokogiri/xml/schema.rb +7 -6
- data/lib/nokogiri/xml/searchable.rb +42 -22
- data/lib/nokogiri/xml/syntax_error.rb +4 -4
- data/lib/nokogiri/xml/text.rb +1 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +2 -1
- data/lib/nokogiri/xml/xpath.rb +12 -0
- data/lib/nokogiri/xml/xpath_context.rb +2 -3
- data/lib/nokogiri/xml.rb +3 -3
- data/lib/nokogiri/xslt/stylesheet.rb +1 -0
- data/lib/nokogiri/xslt.rb +3 -2
- data/lib/nokogiri.rb +19 -16
- data/lib/xsd/xmlparser/nokogiri.rb +25 -24
- metadata +102 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c952d55813c188638a5daba0c1e7ab8f9566c5b7832b098cebd98b3d186ecd6
|
4
|
+
data.tar.gz: f7de12d117ee428672f357a79e55f9c5361667c1aacf14e5748dd42fc97334fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c0a0d6e1c97a2b6d2e68de975120b934d8b467d7b598e909460f936c8d7d4bf7e52f9fe5dd9e4aeed20cc2ab26f257e78a5050f975177cf940482c524b1c25e
|
7
|
+
data.tar.gz: 9432e3175aca11f91c51bdae39fd549031fafee24775290ed21a1dbedc98a9ce5a6b19aefac4e16298bf88c8694b9a342d33c55da08fcef7681c0efd825f8a82
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# Nokogiri
|
4
4
|
|
5
|
-
Nokogiri (鋸) makes it easy and painless to work with XML and HTML from Ruby. It provides a sensible, easy-to-understand API for [reading](https://nokogiri.org/tutorials/parsing_an_html_xml_document.html), writing, [modifying](https://nokogiri.org/tutorials/modifying_an_html_xml_document.html), and [querying](https://nokogiri.org/tutorials/searching_a_xml_html_document.html) documents. It is fast and standards-compliant by relying on native parsers like libxml2 (
|
5
|
+
Nokogiri (鋸) makes it easy and painless to work with XML and HTML from Ruby. It provides a sensible, easy-to-understand API for [reading](https://nokogiri.org/tutorials/parsing_an_html_xml_document.html), writing, [modifying](https://nokogiri.org/tutorials/modifying_an_html_xml_document.html), and [querying](https://nokogiri.org/tutorials/searching_a_xml_html_document.html) documents. It is fast and standards-compliant by relying on native parsers like libxml2 (CRuby) and xerces (JRuby).
|
6
6
|
|
7
7
|
## Guiding Principles
|
8
8
|
|
@@ -30,7 +30,9 @@ Some guiding principles Nokogiri tries to follow:
|
|
30
30
|
[![Appveyor CI](https://ci.appveyor.com/api/projects/status/xj2pqwvlxwuwgr06/branch/main?svg=true)](https://ci.appveyor.com/project/flavorjones/nokogiri/branch/main)
|
31
31
|
|
32
32
|
[![Gem Version](https://badge.fury.io/rb/nokogiri.svg)](https://rubygems.org/gems/nokogiri)
|
33
|
-
[![SemVer compatibility](https://
|
33
|
+
[![SemVer compatibility](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=nokogiri&package-manager=bundler&previous-version=1.11.7&new-version=1.12.5)](https://docs.github.com/en/code-security/supply-chain-security/managing-vulnerabilities-in-your-projects-dependencies/about-dependabot-security-updates#about-compatibility-scores)
|
34
|
+
|
35
|
+
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/5344/badge)](https://bestpractices.coreinfrastructure.org/projects/5344)
|
34
36
|
[![Tidelift dependencies](https://tidelift.com/badges/package/rubygems/nokogiri)](https://tidelift.com/subscription/pkg/rubygems-nokogiri?utm_source=rubygems-nokogiri&utm_medium=referral&utm_campaign=readme)
|
35
37
|
|
36
38
|
|
@@ -78,7 +80,7 @@ Full information and description of our security policy is in [`SECURITY.md`](SE
|
|
78
80
|
|
79
81
|
### Semantic Versioning Policy
|
80
82
|
|
81
|
-
Nokogiri follows [Semantic Versioning](https://semver.org/) (since 2017 or so). [![Dependabot's SemVer compatibility score for Nokogiri](https://
|
83
|
+
Nokogiri follows [Semantic Versioning](https://semver.org/) (since 2017 or so). [![Dependabot's SemVer compatibility score for Nokogiri](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=nokogiri&package-manager=bundler&previous-version=1.11.7&new-version=1.12.5)](https://docs.github.com/en/code-security/supply-chain-security/managing-vulnerabilities-in-your-projects-dependencies/about-dependabot-security-updates#about-compatibility-scores)
|
82
84
|
|
83
85
|
We bump `Major.Minor.Patch` versions following this guidance:
|
84
86
|
|
@@ -105,8 +107,8 @@ We bump `Major.Minor.Patch` versions following this guidance:
|
|
105
107
|
|
106
108
|
Requirements:
|
107
109
|
|
108
|
-
- Ruby >= 2.
|
109
|
-
- JRuby >= 9.
|
110
|
+
- Ruby >= 2.6
|
111
|
+
- JRuby >= 9.3.0.0
|
110
112
|
|
111
113
|
|
112
114
|
### Native Gems: Faster, more reliable installation
|
@@ -115,12 +117,12 @@ Requirements:
|
|
115
117
|
|
116
118
|
### Supported Platforms
|
117
119
|
|
118
|
-
|
120
|
+
Nokogiri ships pre-compiled, "native" gems for the following platforms:
|
119
121
|
|
120
122
|
- Linux: `x86-linux` and `x86_64-linux` (req: `glibc >= 2.17`), including musl platforms like Alpine
|
121
123
|
- Darwin/MacOS: `x86_64-darwin` and `arm64-darwin`
|
122
124
|
- Windows: `x86-mingw32` and `x64-mingw32`
|
123
|
-
- Java: any platform running JRuby 9.
|
125
|
+
- Java: any platform running JRuby 9.3 or higher
|
124
126
|
|
125
127
|
To determine whether your system supports one of these gems, look at the output of `bundle platform` or `ruby -e 'puts Gem::Platform.local.to_s'`.
|
126
128
|
|
data/bin/nokogiri
CHANGED
@@ -1,61 +1,77 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "optparse"
|
5
|
+
require "open-uri"
|
6
|
+
require "uri"
|
7
|
+
require "rubygems"
|
8
|
+
require "nokogiri"
|
9
|
+
autoload :IRB, "irb"
|
8
10
|
|
9
11
|
parse_class = Nokogiri
|
10
12
|
encoding = nil
|
11
13
|
|
12
14
|
# This module provides some tunables with the nokogiri CLI for use in
|
13
15
|
# your ~/.nokogirirc.
|
14
|
-
module Nokogiri
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
16
|
+
module Nokogiri
|
17
|
+
module CLI
|
18
|
+
class << self
|
19
|
+
# Specify the console engine, defaulted to IRB.
|
20
|
+
#
|
21
|
+
# call-seq:
|
22
|
+
# require 'pry'
|
23
|
+
# Nokogiri::CLI.console = Pry
|
24
|
+
attr_writer :console
|
25
|
+
|
26
|
+
def console
|
27
|
+
case @console
|
28
|
+
when Symbol
|
29
|
+
Kernel.const_get(@console)
|
30
|
+
else
|
31
|
+
@console
|
32
|
+
end
|
29
33
|
end
|
34
|
+
|
35
|
+
attr_accessor :rcfile
|
30
36
|
end
|
31
37
|
|
32
|
-
|
38
|
+
self.rcfile = File.expand_path("~/.nokogirirc")
|
39
|
+
self.console = :IRB
|
33
40
|
end
|
41
|
+
end
|
34
42
|
|
35
|
-
|
36
|
-
|
43
|
+
def safe_read(uri_or_path)
|
44
|
+
uri = URI.parse(uri_or_path)
|
45
|
+
case uri
|
46
|
+
when URI::HTTP
|
47
|
+
uri.read
|
48
|
+
when URI::File
|
49
|
+
File.read(uri.path)
|
50
|
+
else
|
51
|
+
File.read(uri_or_path)
|
52
|
+
end
|
37
53
|
end
|
38
54
|
|
39
55
|
opts = OptionParser.new do |opts|
|
40
56
|
opts.banner = "Nokogiri: an HTML, XML, SAX, and Reader parser"
|
41
|
-
opts.define_head
|
42
|
-
opts.separator
|
43
|
-
opts.separator
|
44
|
-
opts.separator
|
45
|
-
opts.separator
|
46
|
-
opts.separator
|
47
|
-
opts.separator
|
48
|
-
opts.separator
|
57
|
+
opts.define_head("Usage: nokogiri <uri|path> [options]")
|
58
|
+
opts.separator("")
|
59
|
+
opts.separator("Examples:")
|
60
|
+
opts.separator(" nokogiri https://www.ruby-lang.org/")
|
61
|
+
opts.separator(" nokogiri ./public/index.html")
|
62
|
+
opts.separator(" curl -s http://www.nokogiri.org | nokogiri -e'p $_.css(\"h1\").length'")
|
63
|
+
opts.separator("")
|
64
|
+
opts.separator("Options:")
|
49
65
|
|
50
66
|
opts.on("--type type", "Parse as type: xml or html (default: auto)", [:xml, :html]) do |v|
|
51
|
-
parse_class = {:
|
67
|
+
parse_class = { xml: Nokogiri::XML, html: Nokogiri::HTML }[v]
|
52
68
|
end
|
53
69
|
|
54
70
|
opts.on("-C file", "Specifies initialization file to load (default #{Nokogiri::CLI.rcfile})") do |v|
|
55
71
|
Nokogiri::CLI.rcfile = v
|
56
72
|
end
|
57
73
|
|
58
|
-
opts.on("-E", "--encoding encoding", "Read as encoding (default: #{encoding ||
|
74
|
+
opts.on("-E", "--encoding encoding", "Read as encoding (default: #{encoding || "none"})") do |v|
|
59
75
|
encoding = v
|
60
76
|
end
|
61
77
|
|
@@ -64,7 +80,7 @@ opts = OptionParser.new do |opts|
|
|
64
80
|
end
|
65
81
|
|
66
82
|
opts.on("--rng <uri|path>", "Validate using this rng file.") do |v|
|
67
|
-
@rng =
|
83
|
+
@rng = Nokogiri::XML::RelaxNG(safe_read(v))
|
68
84
|
end
|
69
85
|
|
70
86
|
opts.on_tail("-?", "--help", "Show this message") do
|
@@ -90,15 +106,10 @@ if File.file?(Nokogiri::CLI.rcfile)
|
|
90
106
|
load Nokogiri::CLI.rcfile
|
91
107
|
end
|
92
108
|
|
93
|
-
if url || $stdin.tty?
|
94
|
-
|
95
|
-
when URI::HTTP
|
96
|
-
@doc = parse_class.parse(uri.read, url, encoding)
|
97
|
-
else
|
98
|
-
@doc = parse_class.parse(open(url).read, nil, encoding)
|
99
|
-
end
|
109
|
+
@doc = if url || $stdin.tty?
|
110
|
+
parse_class.parse(safe_read(url), url, encoding)
|
100
111
|
else
|
101
|
-
|
112
|
+
parse_class.parse($stdin, nil, encoding)
|
102
113
|
end
|
103
114
|
|
104
115
|
$_ = @doc
|
@@ -107,12 +118,14 @@ if @rng
|
|
107
118
|
@rng.validate(@doc).each do |error|
|
108
119
|
puts error.message
|
109
120
|
end
|
110
|
-
|
111
|
-
|
112
|
-
eval
|
113
|
-
|
114
|
-
|
115
|
-
|
121
|
+
elsif @script
|
122
|
+
begin
|
123
|
+
eval(@script, binding, "<main>") # rubocop:disable Security/Eval
|
124
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
125
|
+
warn("ERROR: Exception raised while evaluating '#{@script}'")
|
126
|
+
raise e
|
116
127
|
end
|
128
|
+
else
|
129
|
+
puts "Your document is stored in @doc..."
|
130
|
+
Nokogiri::CLI.console.start
|
117
131
|
end
|
118
|
-
|
data/dependencies.yml
CHANGED
@@ -64,11 +64,10 @@ zlib:
|
|
64
64
|
# SHA-256 hash provided on http://zlib.net/
|
65
65
|
|
66
66
|
libiconv:
|
67
|
-
version: "1.
|
68
|
-
sha256: "
|
69
|
-
# gpg: Signature made Fri
|
67
|
+
version: "1.16"
|
68
|
+
sha256: "e6a1b1b589654277ee790cce3734f07876ac4ccfaecbee8afa0b649cf529cc04"
|
69
|
+
# gpg: Signature made Fri 26 Apr 2019 03:36:38 PM EDT
|
70
70
|
# gpg: using RSA key 4F494A942E4616C2
|
71
|
-
# gpg: Good signature from "Bruno Haible (Open Source Development) <bruno@clisp.org>" [
|
72
|
-
# gpg:
|
73
|
-
# gpg: There is no indication that the signature belongs to the owner.
|
71
|
+
# gpg: Good signature from "Bruno Haible (Open Source Development) <bruno@clisp.org>" [expired]
|
72
|
+
# gpg: Note: This key has expired!
|
74
73
|
# Primary key fingerprint: 68D9 4D8A AEEA D48A E7DC 5B90 4F49 4A94 2E46 16C2
|
@@ -1,31 +1,26 @@
|
|
1
1
|
package nokogiri;
|
2
2
|
|
3
|
-
import
|
4
|
-
import
|
5
|
-
import
|
6
|
-
|
7
|
-
import java.io.ByteArrayInputStream;
|
8
|
-
import java.io.InputStream;
|
9
|
-
import java.io.IOException;
|
10
|
-
import java.util.concurrent.Callable;
|
11
|
-
import java.util.concurrent.ExecutionException;
|
12
|
-
import java.util.concurrent.ExecutorService;
|
13
|
-
import java.util.concurrent.Executors;
|
14
|
-
import java.util.concurrent.Future;
|
15
|
-
import java.util.concurrent.FutureTask;
|
16
|
-
import java.util.concurrent.ThreadFactory;
|
17
|
-
|
18
|
-
import nokogiri.internals.*;
|
19
|
-
|
3
|
+
import nokogiri.internals.ClosedStreamException;
|
4
|
+
import nokogiri.internals.NokogiriBlockingQueueInputStream;
|
5
|
+
import nokogiri.internals.NokogiriHelpers;
|
6
|
+
import nokogiri.internals.ParserContext;
|
20
7
|
import org.jruby.Ruby;
|
21
8
|
import org.jruby.RubyClass;
|
22
9
|
import org.jruby.RubyObject;
|
23
10
|
import org.jruby.anno.JRubyClass;
|
24
11
|
import org.jruby.anno.JRubyMethod;
|
25
|
-
import org.jruby.exceptions.RaiseException;
|
26
12
|
import org.jruby.runtime.ThreadContext;
|
27
13
|
import org.jruby.runtime.builtin.IRubyObject;
|
28
14
|
|
15
|
+
import java.io.ByteArrayInputStream;
|
16
|
+
import java.io.IOException;
|
17
|
+
import java.io.InputStream;
|
18
|
+
import java.util.concurrent.*;
|
19
|
+
|
20
|
+
import static nokogiri.XmlSaxPushParser.terminateExecution;
|
21
|
+
import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
|
22
|
+
import static org.jruby.runtime.Helpers.invoke;
|
23
|
+
|
29
24
|
/**
|
30
25
|
* Class for Nokogiri::HTML4::SAX::PushParser
|
31
26
|
*
|
@@ -134,7 +129,7 @@ public class Html4SaxPushParser extends RubyObject
|
|
134
129
|
|
135
130
|
if (!options.recover && parserTask.getErrorCount() > errorCount0) {
|
136
131
|
terminateTask(context.runtime);
|
137
|
-
throw parserTask.getLastError();
|
132
|
+
throw parserTask.getLastError().toThrowable();
|
138
133
|
}
|
139
134
|
|
140
135
|
return this;
|
@@ -17,6 +17,7 @@ import org.jruby.RubyClass;
|
|
17
17
|
import org.jruby.RubyString;
|
18
18
|
import org.jruby.anno.JRubyClass;
|
19
19
|
import org.jruby.anno.JRubyMethod;
|
20
|
+
import org.jruby.runtime.Block;
|
20
21
|
import org.jruby.runtime.Helpers;
|
21
22
|
import org.jruby.runtime.ThreadContext;
|
22
23
|
import org.jruby.runtime.builtin.IRubyObject;
|
@@ -34,8 +35,6 @@ import org.w3c.dom.NamedNodeMap;
|
|
34
35
|
public class XmlDocumentFragment extends XmlNode
|
35
36
|
{
|
36
37
|
|
37
|
-
private XmlElement fragmentContext;
|
38
|
-
|
39
38
|
public
|
40
39
|
XmlDocumentFragment(Ruby ruby)
|
41
40
|
{
|
@@ -48,9 +47,9 @@ public class XmlDocumentFragment extends XmlNode
|
|
48
47
|
super(ruby, klazz);
|
49
48
|
}
|
50
49
|
|
51
|
-
@JRubyMethod(name = "new", meta = true, required = 1, optional =
|
50
|
+
@JRubyMethod(name = "new", meta = true, required = 1, optional = 3)
|
52
51
|
public static IRubyObject
|
53
|
-
rbNew(ThreadContext context, IRubyObject cls, IRubyObject[] args)
|
52
|
+
rbNew(ThreadContext context, IRubyObject cls, IRubyObject[] args, Block block)
|
54
53
|
{
|
55
54
|
if (args.length < 1) {
|
56
55
|
throw context.runtime.newArgumentError(args.length, 1);
|
@@ -75,11 +74,7 @@ public class XmlDocumentFragment extends XmlNode
|
|
75
74
|
fragment.setDocument(context, doc);
|
76
75
|
fragment.setNode(context.runtime, doc.getDocument().createDocumentFragment());
|
77
76
|
|
78
|
-
|
79
|
-
if (args.length == 3 && args[2] != null && args[2] instanceof XmlElement) {
|
80
|
-
fragment.fragmentContext = (XmlElement)args[2];
|
81
|
-
}
|
82
|
-
Helpers.invoke(context, fragment, "initialize", args);
|
77
|
+
Helpers.invoke(context, fragment, "initialize", args, block);
|
83
78
|
return fragment;
|
84
79
|
}
|
85
80
|
|
@@ -158,12 +153,6 @@ public class XmlDocumentFragment extends XmlNode
|
|
158
153
|
return null;
|
159
154
|
}
|
160
155
|
|
161
|
-
public XmlElement
|
162
|
-
getFragmentContext()
|
163
|
-
{
|
164
|
-
return fragmentContext;
|
165
|
-
}
|
166
|
-
|
167
156
|
@Override
|
168
157
|
public void
|
169
158
|
relink_namespace(ThreadContext context)
|
@@ -80,14 +80,6 @@ public class XmlNamespace extends RubyObject
|
|
80
80
|
return href;
|
81
81
|
}
|
82
82
|
|
83
|
-
void
|
84
|
-
deleteHref()
|
85
|
-
{
|
86
|
-
href = "http://www.w3.org/XML/1998/namespace";
|
87
|
-
hrefRuby = null;
|
88
|
-
attr.getOwnerElement().removeAttributeNode(attr);
|
89
|
-
}
|
90
|
-
|
91
83
|
public static XmlNamespace
|
92
84
|
createFromAttr(Ruby runtime, Attr attr)
|
93
85
|
{
|
@@ -12,6 +12,7 @@ import java.util.*;
|
|
12
12
|
import org.apache.xerces.dom.CoreDocumentImpl;
|
13
13
|
import org.jruby.Ruby;
|
14
14
|
import org.jruby.RubyArray;
|
15
|
+
import org.jruby.RubyBoolean;
|
15
16
|
import org.jruby.RubyClass;
|
16
17
|
import org.jruby.RubyFixnum;
|
17
18
|
import org.jruby.RubyInteger;
|
@@ -35,6 +36,7 @@ import org.w3c.dom.NamedNodeMap;
|
|
35
36
|
import org.w3c.dom.Node;
|
36
37
|
import org.w3c.dom.NodeList;
|
37
38
|
import org.w3c.dom.Text;
|
39
|
+
import org.w3c.dom.Comment;
|
38
40
|
|
39
41
|
import nokogiri.internals.HtmlDomParserContext;
|
40
42
|
import nokogiri.internals.NokogiriHelpers;
|
@@ -303,6 +305,14 @@ public class XmlNode extends RubyObject
|
|
303
305
|
IRubyObject name = args[0];
|
304
306
|
IRubyObject doc = args[1];
|
305
307
|
|
308
|
+
if (!(doc instanceof XmlNode)) {
|
309
|
+
throw context.runtime.newArgumentError("document must be a Nokogiri::XML::Node");
|
310
|
+
}
|
311
|
+
if (!(doc instanceof XmlDocument)) {
|
312
|
+
// TODO: deprecate allowing Node
|
313
|
+
context.runtime.getWarnings().warn("Passing a Node as the second parameter to Node.new is deprecated. Please pass a Document instead, or prefer an alternative constructor like Node#add_child. This will become an error in a future release of Nokogiri.");
|
314
|
+
}
|
315
|
+
|
306
316
|
Document document = asXmlNode(context, doc).getOwnerDocument();
|
307
317
|
if (document == null) {
|
308
318
|
throw context.runtime.newArgumentError("node must have owner document");
|
@@ -421,7 +431,14 @@ public class XmlNode extends RubyObject
|
|
421
431
|
String nsURI = e.lookupNamespaceURI(prefix);
|
422
432
|
this.node = NokogiriHelpers.renameNode(e, nsURI, e.getNodeName());
|
423
433
|
|
424
|
-
if (nsURI == null || nsURI.isEmpty()) {
|
434
|
+
if (nsURI == null || nsURI.isEmpty()) {
|
435
|
+
RubyBoolean ns_inherit =
|
436
|
+
(RubyBoolean)document(context.runtime).getInstanceVariable("@namespace_inheritance");
|
437
|
+
if (ns_inherit.isTrue()) {
|
438
|
+
set_namespace(context, ((XmlNode)parent(context)).namespace(context));
|
439
|
+
}
|
440
|
+
return;
|
441
|
+
}
|
425
442
|
|
426
443
|
String currentPrefix = e.getParentNode().lookupPrefix(nsURI);
|
427
444
|
String currentURI = e.getParentNode().lookupNamespaceURI(prefix);
|
@@ -1571,6 +1588,10 @@ public class XmlNode extends RubyObject
|
|
1571
1588
|
return getNokogiriClass(context.runtime, "Nokogiri::XML::Node").getConstant(type);
|
1572
1589
|
}
|
1573
1590
|
|
1591
|
+
/*
|
1592
|
+
* NOTE that the behavior of this function is very difference from the CRuby implementation, see
|
1593
|
+
* the docstring in ext/nokogiri/xml_node.c for details.
|
1594
|
+
*/
|
1574
1595
|
@JRubyMethod
|
1575
1596
|
public IRubyObject
|
1576
1597
|
line(ThreadContext context)
|
@@ -1578,7 +1599,10 @@ public class XmlNode extends RubyObject
|
|
1578
1599
|
Node root = getOwnerDocument();
|
1579
1600
|
int[] counter = new int[1];
|
1580
1601
|
count(root, counter);
|
1581
|
-
|
1602
|
+
// offset of 2:
|
1603
|
+
// - one because humans start counting at 1 not zero
|
1604
|
+
// - one to account for the XML declaration present in the output
|
1605
|
+
return RubyFixnum.newFixnum(context.runtime, counter[0] + 2);
|
1582
1606
|
}
|
1583
1607
|
|
1584
1608
|
private boolean
|
@@ -1591,9 +1615,14 @@ public class XmlNode extends RubyObject
|
|
1591
1615
|
NodeList list = node.getChildNodes();
|
1592
1616
|
for (int jchild = 0; jchild < list.getLength(); jchild++) {
|
1593
1617
|
Node child = list.item(jchild);
|
1618
|
+
String text = null;
|
1594
1619
|
|
1595
1620
|
if (child instanceof Text) {
|
1596
|
-
|
1621
|
+
text = ((Text)child).getData();
|
1622
|
+
} else if (child instanceof Comment) {
|
1623
|
+
text = ((Comment)child).getData();
|
1624
|
+
}
|
1625
|
+
if (text != null) {
|
1597
1626
|
int textLength = text.length();
|
1598
1627
|
for (int jchar = 0; jchar < textLength; jchar++) {
|
1599
1628
|
if (text.charAt(jchar) == '\n') {
|
@@ -1743,24 +1772,11 @@ public class XmlNode extends RubyObject
|
|
1743
1772
|
e.appendChild(otherNode);
|
1744
1773
|
otherNode = e;
|
1745
1774
|
} else {
|
1746
|
-
addNamespaceURIIfNeeded(otherNode);
|
1747
1775
|
parent.appendChild(otherNode);
|
1748
1776
|
}
|
1749
1777
|
return new Node[] { otherNode };
|
1750
1778
|
}
|
1751
1779
|
|
1752
|
-
private void
|
1753
|
-
addNamespaceURIIfNeeded(Node child)
|
1754
|
-
{
|
1755
|
-
if (this instanceof XmlDocumentFragment && ((XmlDocumentFragment) this).getFragmentContext() != null) {
|
1756
|
-
XmlElement fragmentContext = ((XmlDocumentFragment) this).getFragmentContext();
|
1757
|
-
String namespace_uri = fragmentContext.node.getNamespaceURI();
|
1758
|
-
if (namespace_uri != null && namespace_uri.length() > 0) {
|
1759
|
-
NokogiriHelpers.renameNode(child, namespace_uri, child.getNodeName());
|
1760
|
-
}
|
1761
|
-
}
|
1762
|
-
}
|
1763
|
-
|
1764
1780
|
protected void
|
1765
1781
|
adoptAsPrevSibling(ThreadContext context,
|
1766
1782
|
Node parent,
|
@@ -190,10 +190,6 @@ public class XmlNodeSet extends RubyObject implements NodeList
|
|
190
190
|
result[last++] = n;
|
191
191
|
}
|
192
192
|
|
193
|
-
if (nodeOrNamespace instanceof XmlNamespace) {
|
194
|
-
((XmlNamespace) nodeOrNamespace).deleteHref();
|
195
|
-
}
|
196
|
-
|
197
193
|
nodes = Arrays.copyOf(result, last);
|
198
194
|
|
199
195
|
if (nodes.length < orig.length) {
|
@@ -184,6 +184,18 @@ public class XmlReader extends RubyObject
|
|
184
184
|
return RubyBoolean.newBoolean(context.getRuntime(), !readerNode.hasChildren);
|
185
185
|
}
|
186
186
|
|
187
|
+
@JRubyMethod
|
188
|
+
public IRubyObject
|
189
|
+
encoding(ThreadContext context)
|
190
|
+
{
|
191
|
+
IRubyObject constructor_encoding = getInstanceVariable("@encoding");
|
192
|
+
if (!constructor_encoding.isNil()) {
|
193
|
+
return constructor_encoding;
|
194
|
+
}
|
195
|
+
// TODO: get the parser's detected encoding
|
196
|
+
return context.getRuntime().getNil();
|
197
|
+
}
|
198
|
+
|
187
199
|
@JRubyMethod(meta = true, rest = true)
|
188
200
|
public static IRubyObject
|
189
201
|
from_io(ThreadContext context, IRubyObject cls, IRubyObject args[])
|