nokogiri 1.4.0 → 1.4.1

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 (75) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.autotest +5 -6
  3. data/CHANGELOG.ja.rdoc +47 -11
  4. data/CHANGELOG.rdoc +31 -0
  5. data/Manifest.txt +8 -1
  6. data/README.ja.rdoc +4 -3
  7. data/README.rdoc +9 -1
  8. data/Rakefile +4 -0
  9. data/deps.rip +5 -0
  10. data/ext/nokogiri/extconf.rb +4 -0
  11. data/ext/nokogiri/html_element_description.c +1 -1
  12. data/ext/nokogiri/nokogiri.c +7 -0
  13. data/ext/nokogiri/nokogiri.h +4 -1
  14. data/ext/nokogiri/xml_document.c +3 -5
  15. data/ext/nokogiri/xml_encoding_handler.c +79 -0
  16. data/ext/nokogiri/xml_encoding_handler.h +8 -0
  17. data/ext/nokogiri/xml_namespace.c +8 -0
  18. data/ext/nokogiri/xml_namespace.h +1 -0
  19. data/ext/nokogiri/xml_node.c +61 -41
  20. data/ext/nokogiri/xml_node_set.c +22 -14
  21. data/ext/nokogiri/xml_sax_parser.c +0 -3
  22. data/ext/nokogiri/xml_sax_parser_context.c +2 -0
  23. data/ext/nokogiri/xml_sax_push_parser.c +26 -3
  24. data/ext/nokogiri/xml_syntax_error.c +18 -227
  25. data/lib/nokogiri/css/generated_parser.rb +173 -160
  26. data/lib/nokogiri/css/generated_tokenizer.rb +4 -1
  27. data/lib/nokogiri/css/parser.y +4 -1
  28. data/lib/nokogiri/css/tokenizer.rex +2 -1
  29. data/lib/nokogiri/css/xpath_visitor.rb +2 -0
  30. data/lib/nokogiri/ffi/encoding_handler.rb +42 -0
  31. data/lib/nokogiri/ffi/html/element_description.rb +5 -9
  32. data/lib/nokogiri/ffi/libxml.rb +21 -5
  33. data/lib/nokogiri/ffi/structs/xml_char_encoding_handler.rb +11 -0
  34. data/lib/nokogiri/ffi/structs/xml_document.rb +3 -3
  35. data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +110 -1
  36. data/lib/nokogiri/ffi/xml/dtd.rb +2 -4
  37. data/lib/nokogiri/ffi/xml/node.rb +38 -17
  38. data/lib/nokogiri/ffi/xml/node_set.rb +21 -8
  39. data/lib/nokogiri/ffi/xml/reader.rb +1 -1
  40. data/lib/nokogiri/ffi/xml/sax/parser.rb +1 -8
  41. data/lib/nokogiri/ffi/xml/sax/push_parser.rb +16 -4
  42. data/lib/nokogiri/ffi/xml/syntax_error.rb +9 -2
  43. data/lib/nokogiri/ffi/xslt/stylesheet.rb +12 -9
  44. data/lib/nokogiri/version.rb +1 -1
  45. data/lib/nokogiri/xml/builder.rb +1 -1
  46. data/lib/nokogiri/xml/document.rb +35 -4
  47. data/lib/nokogiri/xml/document_fragment.rb +5 -1
  48. data/lib/nokogiri/xml/fragment_handler.rb +28 -20
  49. data/lib/nokogiri/xml/node.rb +84 -13
  50. data/lib/nokogiri/xml/node_set.rb +19 -2
  51. data/lib/nokogiri/xml/sax/push_parser.rb +1 -1
  52. data/lib/nokogiri/xml/syntax_error.rb +10 -5
  53. data/lib/nokogiri/xslt/stylesheet.rb +1 -1
  54. data/lib/xsd/xmlparser/nokogiri.rb +20 -1
  55. data/test/css/test_parser.rb +5 -0
  56. data/test/css/test_tokenizer.rb +7 -0
  57. data/test/helper.rb +0 -5
  58. data/test/html/test_document_fragment.rb +39 -1
  59. data/test/html/test_node.rb +14 -0
  60. data/test/test_encoding_handler.rb +46 -0
  61. data/test/test_memory_leak.rb +10 -0
  62. data/test/test_nokogiri.rb +5 -1
  63. data/test/test_soap4r_sax.rb +52 -0
  64. data/test/test_xslt_transforms.rb +69 -26
  65. data/test/xml/sax/test_parser_context.rb +7 -0
  66. data/test/xml/sax/test_push_parser.rb +33 -0
  67. data/test/xml/test_document.rb +27 -1
  68. data/test/xml/test_document_fragment.rb +6 -0
  69. data/test/xml/test_node.rb +63 -214
  70. data/test/xml/test_node_reparenting.rb +261 -0
  71. data/test/xml/test_node_set.rb +51 -0
  72. data/test/xml/test_syntax_error.rb +0 -15
  73. metadata +35 -5
  74. metadata.gz.sig +0 -0
  75. data/test/test_gc.rb +0 -15
@@ -146,6 +146,12 @@ module Nokogiri
146
146
  end
147
147
  alias :% :at
148
148
 
149
+ ###
150
+ # Filter this list for nodes that match +expr+
151
+ def filter expr
152
+ find_all { |node| node.matches?(expr) }
153
+ end
154
+
149
155
  ###
150
156
  # Append the class attribute +name+ to all Node objects in the NodeSet.
151
157
  def add_class name
@@ -217,8 +223,8 @@ module Nokogiri
217
223
 
218
224
  ###
219
225
  # Get the inner html of all contained Node objects
220
- def inner_html
221
- collect{|j| j.inner_html}.join('')
226
+ def inner_html *args
227
+ collect{|j| j.inner_html(*args) }.join('')
222
228
  end
223
229
 
224
230
  ###
@@ -295,6 +301,17 @@ module Nokogiri
295
301
  inject(NodeSet.new(document)) { |set, node| set += node.children }
296
302
  end
297
303
 
304
+ ###
305
+ # Returns a new NodeSet containing all the nodes in the NodeSet
306
+ # in reverse order
307
+ def reverse
308
+ node_set = NodeSet.new(document)
309
+ (length - 1).downto(0) do |x|
310
+ node_set.push self[x]
311
+ end
312
+ node_set
313
+ end
314
+
298
315
  ###
299
316
  # Return a nicely formated string representation
300
317
  def inspect
@@ -31,7 +31,7 @@ module Nokogiri
31
31
  ###
32
32
  # Create a new PushParser with +doc+ as the SAX Document, providing
33
33
  # an optional +file_name+ and +encoding+
34
- def initialize(doc = XML::SAX::Document.new, file_name = nil, encoding = 'ASCII')
34
+ def initialize(doc = XML::SAX::Document.new, file_name = nil, encoding = 'UTF-8')
35
35
  @document = doc
36
36
  @encoding = encoding
37
37
  @sax_parser = XML::SAX::Parser.new(doc)
@@ -4,9 +4,16 @@ module Nokogiri
4
4
  # This class provides information about XML SyntaxErrors. These
5
5
  # exceptions are typically stored on Nokogiri::XML::Document#errors.
6
6
  class SyntaxError < ::Nokogiri::SyntaxError
7
- def initialize message
8
- self.message = message
9
- end
7
+ attr_reader :domain
8
+ attr_reader :code
9
+ attr_reader :level
10
+ attr_reader :file
11
+ attr_reader :line
12
+ attr_reader :str1
13
+ attr_reader :str2
14
+ attr_reader :str3
15
+ attr_reader :int1
16
+ attr_reader :column
10
17
 
11
18
  ###
12
19
  # return true if this is a non error
@@ -31,8 +38,6 @@ module Nokogiri
31
38
  def fatal?
32
39
  level == 3
33
40
  end
34
-
35
- alias :to_s :message
36
41
  end
37
42
  end
38
43
  end
@@ -18,7 +18,7 @@ module Nokogiri
18
18
  # +params+ is an array of strings used as XSLT parameters.
19
19
  # returns serialized document
20
20
  def apply_to document, params = []
21
- transform(document, params).to_s
21
+ serialize(transform(document, params))
22
22
  end
23
23
  end
24
24
  end
@@ -62,9 +62,28 @@ module XSD # :nodoc:
62
62
  characters string
63
63
  end
64
64
 
65
- %w{ start_document start_element_namespace end_element_namespace end_document comment }.each do |name|
65
+ def start_element_namespace name, attrs = [], prefix = nil, uri = nil, ns = []
66
+ ###
67
+ # Deal with SAX v1 interface
68
+ name = [prefix, name].compact.join(':')
69
+ attributes = ns.map { |ns_prefix,ns_uri|
70
+ [['xmlns', ns_prefix].compact.join(':'), ns_uri]
71
+ } + attrs.map { |attr|
72
+ [[attr.prefix, attr.localname].compact.join(':'), attr.value]
73
+ }.flatten
74
+ start_element name, attributes
75
+ end
76
+
77
+ def end_element_namespace name, prefix = nil, uri = nil
78
+ ###
79
+ # Deal with SAX v1 interface
80
+ end_element [prefix, name].compact.join(':')
81
+ end
82
+
83
+ %w{ xmldecl start_document end_document comment }.each do |name|
66
84
  class_eval %{ def #{name}(*args); end }
67
85
  end
86
+
68
87
  add_factory(self)
69
88
  end
70
89
  end
@@ -54,6 +54,11 @@ module Nokogiri
54
54
  )
55
55
  end
56
56
 
57
+ def test_has
58
+ assert_xpath "//a[b]", @parser.parse("a:has(b)")
59
+ assert_xpath "//a[b/c]", @parser.parse("a:has(b > c)")
60
+ end
61
+
57
62
  def test_dashmatch
58
63
  assert_xpath "//a[@class = 'bar' or starts-with(@class, concat('bar', '-'))]",
59
64
  @parser.parse("a[@class|='bar']")
@@ -10,6 +10,13 @@ module Nokogiri
10
10
  @scanner = Nokogiri::CSS::Tokenizer.new
11
11
  end
12
12
 
13
+ def test_has
14
+ @scanner.scan("a:has(b)")
15
+ assert_tokens(
16
+ [[:IDENT, "a"], [":", ":"], [:HAS, "has("], [:IDENT, "b"], [:RPAREN, ")"]],
17
+ @scanner)
18
+ end
19
+
13
20
  def test_unicode
14
21
  @scanner.scan("a日本語")
15
22
  assert_tokens([[:IDENT, 'a日本語']], @scanner)
@@ -1,15 +1,10 @@
1
1
  #Process.setrlimit(Process::RLIMIT_CORE, Process::RLIM_INFINITY) unless RUBY_PLATFORM =~ /(java|mswin|mingw)/i
2
2
  $VERBOSE = true
3
- require 'rubygems'
4
3
  require 'test/unit'
5
4
  require 'fileutils'
6
5
  require 'tempfile'
7
6
  require 'pp'
8
7
 
9
- %w(../lib ../ext).each do |path|
10
- $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), path)))
11
- end
12
-
13
8
  require 'nokogiri'
14
9
 
15
10
  warn "#{__FILE__}:#{__LINE__}: libxml version info: #{Nokogiri::VERSION_INFO.inspect}"
@@ -9,6 +9,19 @@ module Nokogiri
9
9
  @html = Nokogiri::HTML.parse(File.read(HTML_FILE), HTML_FILE)
10
10
  end
11
11
 
12
+ def test_ancestors_search
13
+ html = %q{
14
+ <div>
15
+ <ul>
16
+ <li>foo</li>
17
+ </ul>
18
+ </div>
19
+ }
20
+ fragment = Nokogiri::HTML.fragment html
21
+ li = fragment.at('li')
22
+ assert li.matches?('li')
23
+ end
24
+
12
25
  def test_fun_encoding
13
26
  string = %Q(<body>こんにちは</body>)
14
27
  html = Nokogiri::HTML::DocumentFragment.parse(
@@ -26,6 +39,16 @@ module Nokogiri
26
39
  assert_equal @html, fragment.document
27
40
  end
28
41
 
42
+ def test_empty_fragment_should_be_searchable_by_css
43
+ fragment = Nokogiri::HTML.fragment("")
44
+ assert_equal 0, fragment.css("a").size
45
+ end
46
+
47
+ def test_empty_fragment_should_be_searchable
48
+ fragment = Nokogiri::HTML.fragment("")
49
+ assert_equal 0, fragment.search("//a").size
50
+ end
51
+
29
52
  def test_name
30
53
  fragment = Nokogiri::HTML::DocumentFragment.new(@html)
31
54
  assert_equal '#document-fragment', fragment.name
@@ -85,6 +108,22 @@ module Nokogiri
85
108
  assert_equal "<div>b</div>", fragment.to_s
86
109
  end
87
110
 
111
+ def test_html_fragment_with_leading_text_and_newline
112
+ fragment = HTML::Document.new.fragment("First line\nSecond line<br>Broken line")
113
+ assert_equal fragment.to_s, "First line\nSecond line<br>Broken line"
114
+ end
115
+
116
+ def test_html_fragment_with_leading_whitespace_and_text_and_newline
117
+ fragment = HTML::Document.new.fragment(" First line\nSecond line<br>Broken line")
118
+ assert_equal "First line\nSecond line<br>Broken line", fragment.to_s
119
+ end
120
+
121
+ def test_html_fragment_with_leading_entity
122
+ failed = "&quot;test<br/>test&quot;"
123
+ fragment = Nokogiri::HTML::DocumentFragment.parse(failed)
124
+ assert_equal '"test<br>test"', fragment.to_html
125
+ end
126
+
88
127
  def test_to_s
89
128
  doc = "<span>foo<br></span><span>bar</span>"
90
129
  fragment = Nokogiri::HTML::Document.new.fragment(doc)
@@ -126,7 +165,6 @@ module Nokogiri
126
165
  assert_equal("<p>hello<!-- your ad here --></p>",
127
166
  fragment.to_s)
128
167
  end
129
-
130
168
  end
131
169
  end
132
170
  end
@@ -17,6 +17,11 @@ module Nokogiri
17
17
  eohtml
18
18
  end
19
19
 
20
+ def test_attr
21
+ node = @html.at('div.baz')
22
+ assert_equal node['class'], node.attr('class')
23
+ end
24
+
20
25
  def test_get_attribute
21
26
  element = @html.at('div')
22
27
  assert_equal 'baz', element.get_attribute('class')
@@ -78,6 +83,14 @@ module Nokogiri
78
83
  assert_equal 'div', list.first.name
79
84
  end
80
85
 
86
+ def test_matches_inside_fragment
87
+ fragment = DocumentFragment.new @html
88
+ fragment << XML::Node.new('a', @html)
89
+
90
+ a = fragment.children.last
91
+ assert a.matches?('a'), 'a should match'
92
+ end
93
+
81
94
  def test_css_matches?
82
95
  assert node = @html.at('a.bar')
83
96
  assert node.matches?('a.bar')
@@ -205,6 +218,7 @@ module Nokogiri
205
218
  end
206
219
 
207
220
  def test_to_html_does_not_contain_entities
221
+ return unless defined?(NKF) # NKF is not implemented on Rubinius as of 2009-11-23
208
222
  html = NKF.nkf("-e --msdos", <<-EOH)
209
223
  <html><body>
210
224
  <p> test paragraph
@@ -0,0 +1,46 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require "helper"
4
+
5
+ class TestEncodingHandler < Nokogiri::TestCase
6
+ def teardown
7
+ Nokogiri::EncodingHandler.clear_aliases!
8
+ end
9
+
10
+ def test_get
11
+ assert_not_nil Nokogiri::EncodingHandler['UTF-8']
12
+ assert_nil Nokogiri::EncodingHandler['alsdkjfhaldskjfh']
13
+ end
14
+
15
+ def test_name
16
+ eh = Nokogiri::EncodingHandler['UTF-8']
17
+ assert_equal "UTF-8", eh.name
18
+ end
19
+
20
+ def test_alias
21
+ Nokogiri::EncodingHandler.alias('UTF-8', 'UTF-18')
22
+ assert_equal 'UTF-8', Nokogiri::EncodingHandler['UTF-18'].name
23
+ end
24
+
25
+ def test_cleanup_aliases
26
+ assert_nil Nokogiri::EncodingHandler['UTF-9']
27
+ Nokogiri::EncodingHandler.alias('UTF-8', 'UTF-9')
28
+ assert_not_nil Nokogiri::EncodingHandler['UTF-9']
29
+
30
+ Nokogiri::EncodingHandler.clear_aliases!
31
+ assert_nil Nokogiri::EncodingHandler['UTF-9']
32
+ end
33
+
34
+ def test_delete
35
+ assert_nil Nokogiri::EncodingHandler['UTF-9']
36
+ Nokogiri::EncodingHandler.alias('UTF-8', 'UTF-9')
37
+ assert_not_nil Nokogiri::EncodingHandler['UTF-9']
38
+
39
+ Nokogiri::EncodingHandler.delete 'UTF-9'
40
+ assert_nil Nokogiri::EncodingHandler['UTF-9']
41
+ end
42
+
43
+ def test_delete_non_existent
44
+ assert_nil Nokogiri::EncodingHandler.delete('UTF-9')
45
+ end
46
+ end
@@ -4,6 +4,16 @@ class TestMemoryLeak < Nokogiri::TestCase
4
4
 
5
5
  if ENV['NOKOGIRI_GC'] # turning these off by default for now
6
6
 
7
+ def test_dont_hurt_em_why
8
+ content = File.open("#{File.dirname(__FILE__)}/files/dont_hurt_em_why.xml").read
9
+ ndoc = Nokogiri::XML(content)
10
+ 2.times do
11
+ info = ndoc.search('status text').first.inner_text
12
+ url = ndoc.search('user name').first.inner_text
13
+ GC.start
14
+ end
15
+ end
16
+
7
17
  def test_for_memory_leak
8
18
  begin
9
19
  # we don't use Dike in any tests, but requiring it has side effects
@@ -6,7 +6,7 @@ class TestNokogiri < Nokogiri::TestCase
6
6
  assert_match version_match, Nokogiri::VERSION
7
7
  assert_match version_match, Nokogiri::LIBXML_VERSION
8
8
 
9
- if defined?(FFI)
9
+ if defined?(FFI) && defined?(Nokogiri::LibXML)
10
10
  assert_equal 'ffi', Nokogiri::VERSION_INFO['libxml']['binding']
11
11
  if RUBY_PLATFORM =~ /java/
12
12
  assert_equal 'jruby', Nokogiri::VERSION_INFO['libxml']['platform']
@@ -30,6 +30,10 @@ class TestNokogiri < Nokogiri::TestCase
30
30
  assert_equal "#{major}.#{minor}.#{bug}", Nokogiri::VERSION_INFO['libxml']['loaded']
31
31
  end
32
32
 
33
+ def test_libxml_iconv
34
+ assert Nokogiri.const_defined?(:LIBXML_ICONV_ENABLED)
35
+ end
36
+
33
37
  def test_parse_with_io
34
38
  doc = Nokogiri.parse(
35
39
  StringIO.new("<html><head><title></title><body></body></html>")
@@ -0,0 +1,52 @@
1
+ require "helper"
2
+
3
+ module XSD
4
+ module XMLParser
5
+ class Parser
6
+ @factory_added = nil
7
+
8
+ class << self; attr_reader :factory_added; end
9
+
10
+ def self.add_factory o
11
+ @factory_added = o
12
+ end
13
+
14
+ def initialize *args
15
+ @charset = nil
16
+ end
17
+
18
+ def characters foo
19
+ end
20
+
21
+ def start_element *args
22
+ end
23
+
24
+ def end_element *args
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ require 'xsd/xmlparser/nokogiri'
31
+
32
+ class TestSoap4rSax < Nokogiri::TestCase
33
+ def test_factory_added
34
+ assert_equal XSD::XMLParser::Nokogiri, XSD::XMLParser::Nokogiri.factory_added
35
+ end
36
+
37
+ def test_parse
38
+ o = Class.new(::XSD::XMLParser::Nokogiri) do
39
+ attr_accessor :element_started
40
+ def initialize *args
41
+ super
42
+ @element_started = false
43
+ end
44
+
45
+ def start_element *args
46
+ @element_started = true
47
+ end
48
+ end.new 'foo'
49
+ o.do_parse '<?xml version="1.0" ?><root xmlns="http://example.com/"/>'
50
+ assert o.element_started, 'element started'
51
+ end
52
+ end
@@ -2,23 +2,23 @@ require "helper"
2
2
 
3
3
  class TestXsltTransforms < Nokogiri::TestCase
4
4
 
5
+ def setup
6
+ @doc = Nokogiri::XML(File.open(XML_FILE))
7
+ end
8
+
5
9
  if Nokogiri::VERSION_INFO['libxml']['loaded'] > '2.6.16'
6
10
 
7
11
  def test_class_methods
8
- doc = Nokogiri::XML(File.read(XML_FILE))
9
12
  style = Nokogiri::XSLT(File.read(XSLT_FILE))
10
13
 
11
- assert result = style.apply_to(doc, ['title', '"Grandma"'])
14
+ assert result = style.apply_to(@doc, ['title', '"Grandma"'])
12
15
  assert_match %r{<h1>Grandma</h1>}, result
13
16
  end
14
17
 
15
18
  def test_transform
16
- assert doc = Nokogiri::XML.parse(File.read(XML_FILE))
17
- assert doc.xml?
18
-
19
19
  assert style = Nokogiri::XSLT.parse(File.read(XSLT_FILE))
20
20
 
21
- assert result = style.apply_to(doc, ['title', '"Booyah"'])
21
+ assert result = style.apply_to(@doc, ['title', '"Booyah"'])
22
22
  assert_match %r{<h1>Booyah</h1>}, result
23
23
  assert_match %r{<th.*Employee ID</th>}, result
24
24
  assert_match %r{<th.*Name</th>}, result
@@ -31,29 +31,72 @@ class TestXsltTransforms < Nokogiri::TestCase
31
31
  assert_no_match %r{Dallas|Texas}, result
32
32
  assert_no_match %r{Female}, result
33
33
 
34
- assert result = style.apply_to(doc, ['title', '"Grandma"'])
34
+ assert result = style.apply_to(@doc, ['title', '"Grandma"'])
35
35
  assert_match %r{<h1>Grandma</h1>}, result
36
36
 
37
- assert result = style.apply_to(doc)
37
+ assert result = style.apply_to(@doc)
38
38
  assert_match %r{<h1></h1>}, result
39
39
  end
40
40
 
41
- def test_transform2
42
- assert doc = Nokogiri::XML.parse(File.read(XML_FILE))
43
- assert doc.xml?
41
+ def test_transform_with_output_style
42
+ xslt = Nokogiri::XSLT(<<-eoxslt)
43
+ <?xml version="1.0" encoding="ISO-8859-1"?>
44
44
 
45
- assert style = Nokogiri::XSLT.parse(File.read(XSLT_FILE))
46
- assert result_doc = style.transform(doc)
47
- assert doc.xml?
45
+ <xsl:stylesheet version="1.0"
46
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
47
+ <xsl:output method="text" version="1.0"
48
+ encoding="iso-8859-1" indent="yes"/>
49
+
50
+ <xsl:param name="title"/>
51
+
52
+ <xsl:template match="/">
53
+ <html>
54
+ <body>
55
+ <xsl:for-each select="staff/employee">
56
+ <tr>
57
+ <td><xsl:value-of select="employeeId"/></td>
58
+ <td><xsl:value-of select="name"/></td>
59
+ <td><xsl:value-of select="position"/></td>
60
+ <td><xsl:value-of select="salary"/></td>
61
+ </tr>
62
+ </xsl:for-each>
63
+ </table>
64
+ </body>
65
+ </html>
66
+ </xsl:template>
67
+
68
+ </xsl:stylesheet>
69
+ eoxslt
70
+ assert_no_match(/<td>/, xslt.apply_to(@doc, ['title', 'foo']))
71
+ end
48
72
 
49
- assert style = Nokogiri::XSLT.parse(File.read(XSLT_FILE))
50
- assert result_doc = style.transform(doc, ['title', '"Booyah"'])
51
- assert doc.xml?
73
+ def test_transform2
74
+ assert style = Nokogiri::XSLT(File.open(XSLT_FILE))
75
+ assert result_doc = style.transform(@doc)
76
+ assert result_doc.html?
77
+ assert_equal "", result_doc.at_css("h1").content
78
+
79
+ assert style = Nokogiri::XSLT(File.read(XSLT_FILE))
80
+ assert result_doc = style.transform(@doc, ['title', '"Booyah"'])
81
+ assert result_doc.html?
82
+ assert_equal "Booyah", result_doc.at_css("h1").content
52
83
 
53
- assert result_string = style.apply_to(doc, ['title', '"Booyah"'])
84
+ assert result_string = style.apply_to(@doc, ['title', '"Booyah"'])
54
85
  assert_equal result_string, style.serialize(result_doc)
55
86
  end
56
87
 
88
+ def test_transform_with_quote_params
89
+ assert style = Nokogiri::XSLT(File.open(XSLT_FILE))
90
+ assert result_doc = style.transform(@doc, Nokogiri::XSLT.quote_params(['title', 'Booyah']))
91
+ assert result_doc.html?
92
+ assert_equal "Booyah", result_doc.at_css("h1").content
93
+
94
+ assert style = Nokogiri::XSLT.parse(File.read(XSLT_FILE))
95
+ assert result_doc = style.transform(@doc, Nokogiri::XSLT.quote_params({'title' => 'Booyah'}))
96
+ assert result_doc.html?
97
+ assert_equal "Booyah", result_doc.at_css("h1").content
98
+ end
99
+
57
100
  def test_quote_params
58
101
  h = {
59
102
  :sym => %{xxx},
@@ -64,7 +107,7 @@ class TestXsltTransforms < Nokogiri::TestCase
64
107
  }
65
108
  hh=h.dup
66
109
  result_hash = Nokogiri::XSLT.quote_params(h)
67
- assert_equal hh, h # non-destructive
110
+ assert_equal hh, h # non-destructive
68
111
 
69
112
  a=h.to_a.flatten
70
113
  result_array = Nokogiri::XSLT.quote_params(a)
@@ -76,32 +119,32 @@ class TestXsltTransforms < Nokogiri::TestCase
76
119
  def test_exslt
77
120
  assert doc = Nokogiri::XML.parse(File.read(EXML_FILE))
78
121
  assert doc.xml?
79
-
122
+
80
123
  assert style = Nokogiri::XSLT.parse(File.read(EXSLT_FILE))
81
- params = {
124
+ params = {
82
125
  :p1 => 'xxx',
83
126
  :p2 => "x'x'x",
84
127
  :p3 => 'x"x"x',
85
128
  :p4 => '"xxx"'
86
129
  }
87
- result_doc = Nokogiri::XML.parse(style.apply_to(doc,
130
+ result_doc = Nokogiri::XML.parse(style.apply_to(doc,
88
131
  Nokogiri::XSLT.quote_params(params)))
89
-
132
+
90
133
  assert_equal 'func-result', result_doc.at('/root/function').content
91
134
  assert_equal 3, result_doc.at('/root/max').content.to_i
92
135
  assert_match(
93
- /\d{4}-\d\d-\d\d[-|+]\d\d:\d\d/,
136
+ /\d{4}-\d\d-\d\d([-|+]\d\d:\d\d)?/,
94
137
  result_doc.at('/root/date').content
95
138
  )
96
139
  result_doc.xpath('/root/params/*').each do |p|
97
140
  assert_equal p.content, params[p.name.intern]
98
141
  end
99
142
  check_params result_doc, params
100
- result_doc = Nokogiri::XML.parse(style.apply_to(doc,
143
+ result_doc = Nokogiri::XML.parse(style.apply_to(doc,
101
144
  Nokogiri::XSLT.quote_params(params.to_a.flatten)))
102
145
  check_params result_doc, params
103
146
  end
104
-
147
+
105
148
  def test_xslt_parse_error
106
149
  xslt_str = <<-EOX
107
150
  <xsl:stylesheet version="1.0"