nokogiri 1.5.0-x86-mswin32-60 → 1.5.1.rc1-x86-mswin32-60
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.
- data/CHANGELOG.ja.rdoc +39 -12
- data/CHANGELOG.rdoc +28 -0
- data/C_CODING_STYLE.rdoc +27 -0
- data/Manifest.txt +4 -0
- data/README.rdoc +11 -7
- data/Rakefile +40 -25
- data/bin/nokogiri +10 -2
- data/ext/nokogiri/extconf.rb +9 -1
- data/ext/nokogiri/html_document.c +16 -0
- data/ext/nokogiri/html_sax_parser_context.c +59 -37
- data/ext/nokogiri/html_sax_push_parser.c +87 -0
- data/ext/nokogiri/html_sax_push_parser.h +9 -0
- data/ext/nokogiri/nokogiri.c +6 -8
- data/ext/nokogiri/nokogiri.h +3 -0
- data/ext/nokogiri/xml_document.c +101 -3
- data/ext/nokogiri/xml_document.h +3 -3
- data/ext/nokogiri/xml_node.c +150 -58
- data/ext/nokogiri/xml_node_set.c +169 -120
- data/ext/nokogiri/xml_node_set.h +5 -0
- data/ext/nokogiri/xml_sax_parser_context.c +64 -41
- data/ext/nokogiri/xml_text.c +2 -0
- data/ext/nokogiri/xml_xpath_context.c +30 -24
- data/ext/nokogiri/xslt_stylesheet.c +62 -16
- data/ext/nokogiri/xslt_stylesheet.h +5 -0
- data/lib/nokogiri/1.8/nokogiri.so +0 -0
- data/lib/nokogiri/1.9/nokogiri.so +0 -0
- data/lib/nokogiri/css/parser.rb +165 -159
- data/lib/nokogiri/css/parser.y +6 -3
- data/lib/nokogiri/css/tokenizer.rb +1 -1
- data/lib/nokogiri/css/tokenizer.rex +1 -1
- data/lib/nokogiri/html.rb +1 -0
- data/lib/nokogiri/html/document.rb +82 -42
- data/lib/nokogiri/html/sax/push_parser.rb +16 -0
- data/lib/nokogiri/version.rb +1 -1
- data/lib/nokogiri/xml.rb +6 -0
- data/lib/nokogiri/xml/builder.rb +7 -1
- data/lib/nokogiri/xml/document.rb +32 -17
- data/lib/nokogiri/xml/document_fragment.rb +6 -1
- data/lib/nokogiri/xml/node.rb +40 -9
- data/lib/nokogiri/xslt.rb +5 -1
- data/tasks/cross_compile.rb +1 -0
- data/tasks/nokogiri.org.rb +6 -0
- data/tasks/test.rb +1 -0
- data/test/css/test_xpath_visitor.rb +6 -0
- data/test/helper.rb +1 -0
- data/test/html/test_document.rb +26 -0
- data/test/html/test_document_fragment.rb +1 -2
- data/test/test_memory_leak.rb +81 -1
- data/test/test_xslt_transforms.rb +152 -123
- data/test/xml/test_builder.rb +24 -2
- data/test/xml/test_c14n.rb +151 -0
- data/test/xml/test_document.rb +48 -0
- data/test/xml/test_namespace.rb +5 -0
- data/test/xml/test_node.rb +82 -1
- data/test/xml/test_node_attributes.rb +19 -0
- data/test/xml/test_node_inheritance.rb +32 -0
- data/test/xml/test_node_reparenting.rb +32 -0
- data/test/xml/test_node_set.rb +16 -8
- data/test/xml/test_reader_encoding.rb +16 -0
- data/test/xml/test_unparented_node.rb +24 -0
- data/test/xml/test_xinclude.rb +83 -0
- data/test/xml/test_xpath.rb +22 -0
- metadata +159 -126
data/lib/nokogiri/xslt.rb
CHANGED
@@ -26,7 +26,11 @@ module Nokogiri
|
|
26
26
|
XSLT.register url, klass
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
if Nokogiri.jruby?
|
30
|
+
Stylesheet.parse_stylesheet_doc(XML.parse(string), string)
|
31
|
+
else
|
32
|
+
Stylesheet.parse_stylesheet_doc(XML.parse(string))
|
33
|
+
end
|
30
34
|
end
|
31
35
|
|
32
36
|
###
|
data/tasks/cross_compile.rb
CHANGED
data/tasks/nokogiri.org.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
+
#
|
2
|
+
# note that this file will only work if you've got the `nokogiri.org`
|
3
|
+
# repo checked out, and you've got an rvm gemset "1.8.7@nokogiri"
|
4
|
+
# bundled with both nokogiri's and nokogiri.org's gems.
|
5
|
+
#
|
1
6
|
namespace :docs do
|
2
7
|
desc "generate HTML docs for nokogiri.org"
|
3
8
|
task :website do
|
9
|
+
system 'rvm use 1.8.7@nokogiri' # see above
|
4
10
|
title = "#{HOE.name}-#{HOE.version} Documentation"
|
5
11
|
|
6
12
|
options = []
|
data/tasks/test.rb
CHANGED
@@ -28,6 +28,12 @@ module Nokogiri
|
|
28
28
|
assert_xpath("//a", @parser.parse('|a'))
|
29
29
|
end
|
30
30
|
|
31
|
+
def test_namespaced_attribute_conversion
|
32
|
+
assert_xpath("//a[@flavorjones:href]", @parser.parse('a[flavorjones|href]'))
|
33
|
+
assert_xpath("//a[@href]", @parser.parse('a[|href]'))
|
34
|
+
assert_xpath("//*[@flavorjones:href]", @parser.parse('*[flavorjones|href]'))
|
35
|
+
end
|
36
|
+
|
31
37
|
def test_unknown_psuedo_classes_get_pushed_down
|
32
38
|
assert_xpath("//a[aaron(.)]", @parser.parse('a:aaron'))
|
33
39
|
end
|
data/test/helper.rb
CHANGED
@@ -29,6 +29,7 @@ module Nokogiri
|
|
29
29
|
ADDRESS_SCHEMA_FILE = File.join(ASSETS_DIR, 'address_book.rlx')
|
30
30
|
ADDRESS_XML_FILE = File.join(ASSETS_DIR, 'address_book.xml')
|
31
31
|
SNUGGLES_FILE = File.join(ASSETS_DIR, 'snuggles.xml')
|
32
|
+
XML_XINCLUDE_FILE = File.join(ASSETS_DIR, 'xinclude.xml')
|
32
33
|
|
33
34
|
def teardown
|
34
35
|
if ENV['NOKOGIRI_GC']
|
data/test/html/test_document.rb
CHANGED
@@ -199,6 +199,32 @@ eohtml
|
|
199
199
|
assert_nil html.meta_encoding
|
200
200
|
end
|
201
201
|
|
202
|
+
def test_meta_encoding_with_empty_content_type
|
203
|
+
html = Nokogiri::HTML(<<-eohtml)
|
204
|
+
<html>
|
205
|
+
<head>
|
206
|
+
<meta http-equiv="Content-Type" content="">
|
207
|
+
</head>
|
208
|
+
<body>
|
209
|
+
foo
|
210
|
+
</body>
|
211
|
+
</html>
|
212
|
+
eohtml
|
213
|
+
assert_nil html.meta_encoding
|
214
|
+
|
215
|
+
html = Nokogiri::HTML(<<-eohtml)
|
216
|
+
<html>
|
217
|
+
<head>
|
218
|
+
<meta http-equiv="Content-Type">
|
219
|
+
</head>
|
220
|
+
<body>
|
221
|
+
foo
|
222
|
+
</body>
|
223
|
+
</html>
|
224
|
+
eohtml
|
225
|
+
assert_nil html.meta_encoding
|
226
|
+
end
|
227
|
+
|
202
228
|
def test_root_node_parent_is_document
|
203
229
|
parent = @html.root.parent
|
204
230
|
assert_equal @html, parent
|
@@ -190,8 +190,7 @@ module Nokogiri
|
|
190
190
|
def test_to_xhtml
|
191
191
|
doc = "<span>foo<br></span><span>bar</span>"
|
192
192
|
fragment = Nokogiri::HTML::Document.new.fragment(doc)
|
193
|
-
if !Nokogiri.
|
194
|
-
Nokogiri::VERSION_INFO['libxml']['loaded'] >= "2.7.0"
|
193
|
+
if !Nokogiri.jruby? && Nokogiri::VERSION_INFO['libxml']['loaded'] >= "2.7.0"
|
195
194
|
assert_equal "<span>foo<br /></span><span>bar</span>", fragment.to_xhtml
|
196
195
|
else
|
197
196
|
assert_equal "<span>foo<br></span><span>bar</span>", fragment.to_xhtml
|
data/test/test_memory_leak.rb
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
require "helper"
|
2
2
|
|
3
3
|
class TestMemoryLeak < Nokogiri::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
@str = <<EOF
|
7
|
+
<!DOCTYPE HTML>
|
8
|
+
<html>
|
9
|
+
<body>
|
10
|
+
<br />
|
11
|
+
</body>
|
12
|
+
</html>
|
13
|
+
EOF
|
14
|
+
end
|
15
|
+
|
4
16
|
if ENV['NOKOGIRI_GC'] # turning these off by default for now
|
5
17
|
def test_dont_hurt_em_why
|
6
18
|
content = File.open("#{File.dirname(__FILE__)}/files/dont_hurt_em_why.xml").read
|
@@ -26,7 +38,7 @@ class TestMemoryLeak < Nokogiri::TestCase
|
|
26
38
|
io = File.open SNUGGLES_FILE
|
27
39
|
Nokogiri::XML.parse(io)
|
28
40
|
|
29
|
-
|
41
|
+
loop do
|
30
42
|
Nokogiri::XML.parse(BadIO.new) rescue nil
|
31
43
|
doc.write BadIO.new rescue nil
|
32
44
|
end
|
@@ -60,6 +72,74 @@ class TestMemoryLeak < Nokogiri::TestCase
|
|
60
72
|
puts "\ndike is not installed, skipping memory leak test"
|
61
73
|
end
|
62
74
|
end
|
75
|
+
|
76
|
+
def test_node_set_namespace_mem_leak
|
77
|
+
xml = Nokogiri::XML "<foo></foo>"
|
78
|
+
ctx = Nokogiri::XML::XPathContext.new(xml)
|
79
|
+
loop do
|
80
|
+
ctx.evaluate("//namespace::*")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_leak_on_node_replace
|
85
|
+
loop do
|
86
|
+
doc = Nokogiri.XML("<root><foo /></root>")
|
87
|
+
n = Nokogiri::XML::CDATA.new(doc, "bar")
|
88
|
+
pivot = doc.root.children[0]
|
89
|
+
pivot.replace(n)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_sax_parser_context
|
94
|
+
io = StringIO.new(@str)
|
95
|
+
|
96
|
+
loop do
|
97
|
+
Nokogiri::XML::SAX::ParserContext.new(@str)
|
98
|
+
Nokogiri::XML::SAX::ParserContext.new(io)
|
99
|
+
io.rewind
|
100
|
+
|
101
|
+
Nokogiri::HTML::SAX::ParserContext.new(@str)
|
102
|
+
Nokogiri::HTML::SAX::ParserContext.new(io)
|
103
|
+
io.rewind
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class JumpingSaxHandler < Nokogiri::XML::SAX::Document
|
108
|
+
def initialize(jumptag)
|
109
|
+
@jumptag = jumptag
|
110
|
+
super()
|
111
|
+
end
|
112
|
+
|
113
|
+
def start_element(name, attrs = [])
|
114
|
+
throw @jumptag
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_jumping_sax_handler
|
119
|
+
doc = JumpingSaxHandler.new(:foo)
|
120
|
+
|
121
|
+
loop do
|
122
|
+
catch(:foo) do
|
123
|
+
Nokogiri::HTML::SAX::Parser.new(doc).parse(@str)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_in_context_parser_leak
|
129
|
+
loop do
|
130
|
+
doc = Nokogiri::XML::Document.new
|
131
|
+
fragment1 = Nokogiri::XML::DocumentFragment.new(doc, '<foo/>')
|
132
|
+
node = fragment1.children[0]
|
133
|
+
node.parse('<bar></bar>')
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_leak_on_xpath_string_function
|
138
|
+
doc = Nokogiri::XML(@str)
|
139
|
+
loop do
|
140
|
+
doc.xpath('name(//node())')
|
141
|
+
end
|
142
|
+
end
|
63
143
|
end # if NOKOGIRI_GC
|
64
144
|
|
65
145
|
private
|
@@ -5,38 +5,39 @@ class TestXsltTransforms < Nokogiri::TestCase
|
|
5
5
|
@doc = Nokogiri::XML(File.open(XML_FILE))
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
style = Nokogiri::XSLT(File.read(XSLT_FILE))
|
8
|
+
def test_class_methods
|
9
|
+
style = Nokogiri::XSLT(File.read(XSLT_FILE))
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
assert result = style.apply_to(@doc, ['title', '"Grandma"'])
|
12
|
+
assert_match %r{<h1>Grandma</h1>}, result
|
13
|
+
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
15
|
+
def test_transform
|
16
|
+
assert style = Nokogiri::XSLT.parse(File.read(XSLT_FILE))
|
17
|
+
|
18
|
+
assert result = style.apply_to(@doc, ['title', '"Booyah"'])
|
19
|
+
assert_match %r{<h1>Booyah</h1>}, result
|
20
|
+
assert_match %r{<th.*Employee ID</th>}, result
|
21
|
+
assert_match %r{<th.*Name</th>}, result
|
22
|
+
assert_match %r{<th.*Position</th>}, result
|
23
|
+
assert_match %r{<th.*Salary</th>}, result
|
24
|
+
assert_match %r{<td>EMP0003</td>}, result
|
25
|
+
assert_match %r{<td>Margaret Martin</td>}, result
|
26
|
+
assert_match %r{<td>Computer Specialist</td>}, result
|
27
|
+
assert_match %r{<td>100,000</td>}, result
|
28
|
+
assert_no_match %r{Dallas|Texas}, result
|
29
|
+
assert_no_match %r{Female}, result
|
30
|
+
|
31
|
+
assert result = style.apply_to(@doc, ['title', '"Grandma"'])
|
32
|
+
assert_match %r{<h1>Grandma</h1>}, result
|
33
|
+
|
34
|
+
assert result = style.apply_to(@doc)
|
35
|
+
assert_match %r{<h1></h1>}, result
|
36
|
+
end
|
38
37
|
|
39
|
-
|
38
|
+
def test_transform_with_output_style
|
39
|
+
xslt = ""
|
40
|
+
if Nokogiri.jruby?
|
40
41
|
xslt = Nokogiri::XSLT(<<-eoxslt)
|
41
42
|
<?xml version="1.0" encoding="ISO-8859-1"?>
|
42
43
|
|
@@ -58,109 +59,138 @@ encoding="iso-8859-1" indent="yes"/>
|
|
58
59
|
<td><xsl:value-of select="salary"/></td>
|
59
60
|
</tr>
|
60
61
|
</xsl:for-each>
|
61
|
-
</table>
|
62
62
|
</body>
|
63
63
|
</html>
|
64
64
|
</xsl:template>
|
65
65
|
|
66
66
|
</xsl:stylesheet>
|
67
67
|
eoxslt
|
68
|
-
|
69
|
-
|
68
|
+
else
|
69
|
+
xslt = Nokogiri::XSLT(<<-eoxslt)
|
70
|
+
<?xml version="1.0" encoding="ISO-8859-1"?>
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
76
|
-
end
|
72
|
+
<xsl:stylesheet version="1.0"
|
73
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
74
|
+
<xsl:output method="text" version="1.0"
|
75
|
+
encoding="iso-8859-1" indent="yes"/>
|
77
76
|
|
78
|
-
|
79
|
-
assert style = Nokogiri::XSLT(File.read(XSLT_FILE))
|
80
|
-
result = style.transform(@doc, {'title' => '"Booyah"'})
|
81
|
-
assert result.html?
|
82
|
-
assert_equal "Booyah", result.at_css("h1").content
|
83
|
-
end
|
77
|
+
<xsl:param name="title"/>
|
84
78
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
79
|
+
<xsl:template match="/">
|
80
|
+
<html>
|
81
|
+
<body>
|
82
|
+
<xsl:for-each select="staff/employee">
|
83
|
+
<tr>
|
84
|
+
<td><xsl:value-of select="employeeId"/></td>
|
85
|
+
<td><xsl:value-of select="name"/></td>
|
86
|
+
<td><xsl:value-of select="position"/></td>
|
87
|
+
<td><xsl:value-of select="salary"/></td>
|
88
|
+
</tr>
|
89
|
+
</xsl:for-each>
|
90
|
+
</table>
|
91
|
+
</body>
|
92
|
+
</html>
|
93
|
+
</xsl:template>
|
90
94
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
+
</xsl:stylesheet>
|
96
|
+
eoxslt
|
97
|
+
end
|
98
|
+
assert_no_match(/<td>/, xslt.apply_to(@doc, ['title', 'foo']))
|
99
|
+
end
|
95
100
|
|
96
|
-
|
97
|
-
|
101
|
+
def test_transform_arg_error
|
102
|
+
assert style = Nokogiri::XSLT(File.read(XSLT_FILE))
|
103
|
+
assert_raises(TypeError) do
|
104
|
+
style.transform(@doc, :foo)
|
98
105
|
end
|
106
|
+
end
|
99
107
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
108
|
+
def test_transform_with_hash
|
109
|
+
assert style = Nokogiri::XSLT(File.read(XSLT_FILE))
|
110
|
+
result = style.transform(@doc, {'title' => '"Booyah"'})
|
111
|
+
assert result.html?
|
112
|
+
assert_equal "Booyah", result.at_css("h1").content
|
113
|
+
end
|
105
114
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
115
|
+
def test_transform2
|
116
|
+
assert style = Nokogiri::XSLT(File.open(XSLT_FILE))
|
117
|
+
assert result_doc = style.transform(@doc)
|
118
|
+
assert result_doc.html?
|
119
|
+
assert_equal "", result_doc.at_css("h1").content
|
111
120
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
:sym2 => %{'xxx'},
|
117
|
-
'str2' => %{x'x'x},
|
118
|
-
:sym3 => %{x"x"x},
|
119
|
-
}
|
120
|
-
hh=h.dup
|
121
|
-
result_hash = Nokogiri::XSLT.quote_params(h)
|
122
|
-
assert_equal hh, h # non-destructive
|
121
|
+
assert style = Nokogiri::XSLT(File.read(XSLT_FILE))
|
122
|
+
assert result_doc = style.transform(@doc, ['title', '"Booyah"'])
|
123
|
+
assert result_doc.html?
|
124
|
+
assert_equal "Booyah", result_doc.at_css("h1").content
|
123
125
|
|
124
|
-
|
125
|
-
|
126
|
-
|
126
|
+
assert result_string = style.apply_to(@doc, ['title', '"Booyah"'])
|
127
|
+
assert_equal result_string, style.serialize(result_doc)
|
128
|
+
end
|
127
129
|
|
128
|
-
|
129
|
-
|
130
|
+
def test_transform_with_quote_params
|
131
|
+
assert style = Nokogiri::XSLT(File.open(XSLT_FILE))
|
132
|
+
assert result_doc = style.transform(@doc, Nokogiri::XSLT.quote_params(['title', 'Booyah']))
|
133
|
+
assert result_doc.html?
|
134
|
+
assert_equal "Booyah", result_doc.at_css("h1").content
|
135
|
+
|
136
|
+
assert style = Nokogiri::XSLT.parse(File.read(XSLT_FILE))
|
137
|
+
assert result_doc = style.transform(@doc, Nokogiri::XSLT.quote_params({'title' => 'Booyah'}))
|
138
|
+
assert result_doc.html?
|
139
|
+
assert_equal "Booyah", result_doc.at_css("h1").content
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_quote_params
|
143
|
+
h = {
|
144
|
+
:sym => %{xxx},
|
145
|
+
'str' => %{"xxx"},
|
146
|
+
:sym2 => %{'xxx'},
|
147
|
+
'str2' => %{x'x'x},
|
148
|
+
:sym3 => %{x"x"x},
|
149
|
+
}
|
150
|
+
hh=h.dup
|
151
|
+
result_hash = Nokogiri::XSLT.quote_params(h)
|
152
|
+
assert_equal hh, h # non-destructive
|
153
|
+
|
154
|
+
a=h.to_a.flatten
|
155
|
+
result_array = Nokogiri::XSLT.quote_params(a)
|
156
|
+
assert_equal h.to_a.flatten, a #non-destructive
|
157
|
+
|
158
|
+
assert_equal result_array, result_hash
|
159
|
+
end
|
130
160
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
end
|
155
|
-
check_params result_doc, params
|
156
|
-
result_doc = Nokogiri::XML.parse(style.apply_to(doc,
|
157
|
-
Nokogiri::XSLT.quote_params(params.to_a.flatten)))
|
158
|
-
check_params result_doc, params
|
161
|
+
if Nokogiri.uses_libxml? # By now, cannot get it working on JRuby.
|
162
|
+
def test_exslt
|
163
|
+
assert doc = Nokogiri::XML.parse(File.read(EXML_FILE))
|
164
|
+
assert doc.xml?
|
165
|
+
|
166
|
+
assert style = Nokogiri::XSLT.parse(File.read(EXSLT_FILE))
|
167
|
+
params = {
|
168
|
+
:p1 => 'xxx',
|
169
|
+
:p2 => "x'x'x",
|
170
|
+
:p3 => 'x"x"x',
|
171
|
+
:p4 => '"xxx"'
|
172
|
+
}
|
173
|
+
result_doc = Nokogiri::XML.parse(style.apply_to(doc,
|
174
|
+
Nokogiri::XSLT.quote_params(params)))
|
175
|
+
|
176
|
+
assert_equal 'func-result', result_doc.at('/root/function').content
|
177
|
+
assert_equal 3, result_doc.at('/root/max').content.to_i
|
178
|
+
assert_match(
|
179
|
+
/\d{4}-\d\d-\d\d([-|+]\d\d:\d\d)?/,
|
180
|
+
result_doc.at('/root/date').content
|
181
|
+
)
|
182
|
+
result_doc.xpath('/root/params/*').each do |p|
|
183
|
+
assert_equal p.content, params[p.name.intern]
|
159
184
|
end
|
185
|
+
check_params result_doc, params
|
186
|
+
result_doc = Nokogiri::XML.parse(style.apply_to(doc,
|
187
|
+
Nokogiri::XSLT.quote_params(params.to_a.flatten)))
|
188
|
+
check_params result_doc, params
|
160
189
|
end
|
190
|
+
end
|
161
191
|
|
162
|
-
|
163
|
-
|
192
|
+
def test_xslt_parse_error
|
193
|
+
xslt_str = <<-EOX
|
164
194
|
<xsl:stylesheet version="1.0"
|
165
195
|
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
166
196
|
<!-- Not well-formed: -->
|
@@ -174,20 +204,19 @@ encoding="iso-8859-1" indent="yes"/>
|
|
174
204
|
</values>
|
175
205
|
</xsl:template>
|
176
206
|
</xsl:stylesheet>}
|
177
|
-
|
178
|
-
|
179
|
-
|
207
|
+
EOX
|
208
|
+
assert_raises(RuntimeError) { Nokogiri::XSLT.parse(xslt_str) }
|
209
|
+
end
|
180
210
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
211
|
+
def test_passing_a_non_document_to_transform
|
212
|
+
xsl = Nokogiri::XSLT('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"></xsl:stylesheet>')
|
213
|
+
assert_raises(ArgumentError) { xsl.transform("<div></div>") }
|
214
|
+
assert_raises(ArgumentError) { xsl.transform(Nokogiri::HTML("").css("body")) }
|
215
|
+
end
|
186
216
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
end
|
217
|
+
def check_params result_doc, params
|
218
|
+
result_doc.xpath('/root/params/*').each do |p|
|
219
|
+
assert_equal p.content, params[p.name.intern]
|
191
220
|
end
|
192
221
|
end
|
193
222
|
end
|