From 0f20b57dc6b4fcd86ad6e764fde892d42f3add98 Mon Sep 17 00:00:00 2001
From: Radu Preotiuc <49693472+radupr@users.noreply.github.com>
Date: Tue, 16 Jul 2019 16:15:28 -0400
Subject: [PATCH 01/18] Initial setup of salsify fork of libxml-ruby (#1)
* Initial setup
* Modified README file
---
.travis.yml | 12 ---
Gemfile | 6 +-
README.rdoc | 47 ++++-----
Rakefile | 6 +-
ext/libxml/extconf.rb | 95 +++++++++++--------
...uby.gemspec => salsify_libxml_ruby.gemspec | 26 +++--
6 files changed, 93 insertions(+), 99 deletions(-)
delete mode 100644 .travis.yml
rename libxml-ruby.gemspec => salsify_libxml_ruby.gemspec (67%)
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index cf555e3b..00000000
--- a/.travis.yml
+++ /dev/null
@@ -1,12 +0,0 @@
-language: ruby
-sudo: required
-
-before_install:
- - sudo apt-get install -y libxml2-dev
-
-script:
-- rake compile
-- rake test
-
-rvm:
- - 2.5.0
diff --git a/Gemfile b/Gemfile
index b42b1ad4..623def94 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,3 +1,7 @@
-source "https://www.rubygems.org"
+source 'https://gems.salsify.com'
+# override the :github shortcut to be secure by using HTTPS
+git_source(:github) { |repo_name| "https://github.com/#{repo_name}.git" }
+
+# Specify your gem's dependencies in salsify_libxml_ruby.gemspec
gemspec
diff --git a/README.rdoc b/README.rdoc
index b72cf69f..4d1b93fe 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -1,4 +1,23 @@
-= LibXML Ruby
+= Salsify LibXML Ruby
+The libxml_ruby gem provides bindings for libxml library. The Salsify version
+of this gem adds static linking to a locally-compiled version of libxml2
+whose version can be set in extconf.rb. This isolates it from changes to the
+underlying native library, which follows the model of a much better known
+Ruby library binding to libxml2 (Nokogiri) and is especially important in
+this case due to the use of bindings to undocumented APIs.
+
+== SECURITY
+The maintainers will periodically provide security updates for libxml, but
+YOU SHOULD NOT USE this library in production environments.
+
+== INSTALLATION
+Add a reference to "salsify_libxml_ruby" in your Gemfile. This assumes
+that bundler is configured to use https://gems.salisfy.com.
+
+== Original library
+Original README offering more information about this library follows.
+
+== LibXML Ruby
== Overview
The libxml gem provides Ruby language bindings for GNOME's Libxml2
@@ -10,32 +29,6 @@ We think libxml-ruby is the best XML library for Ruby because:
* Features - It provides an amazing number of featues
* Conformance - It passes all 1800+ tests from the OASIS XML Tests Suite
-== Requirements
-libxml-ruby requires Ruby 1.8.7 or higher. It depends on libxml2 to
-function propoerly. libxml2, in turn, depends on:
-
-* libm (math routines: very standard)
-* libz (zlib)
-* libiconv
-
-If you are running Linux or Unix you'll need a C compiler so the
-extension can be compiled when it is installed. If you are running
-Windows, then install the x64-mingw32 gem or build it yourself using
-Devkit (http://rubyinstaller.org/add-ons/devkit/) or
-msys2 (https://msys2.github.io/).
-
-== INSTALLATION
-The easiest way to install libxml-ruby is via Ruby Gems. To install:
-
-gem install libxml-ruby
-
-If you are running Windows, then install the libxml-ruby-x64-mingw32 gem.
-THe gem inncludes prebuilt extensions for Ruby 2.3. These
-extensions are built using MinGW64 and libxml2 version 2.9.3,
-iconv version 1.14 and zlib version 1.2.8. Note these binaries
-are available in the lib\libs directory. To use them, put them
-someplace on your path.
-
The gem also includes a Microsoft VC++ 2012 solution and XCode 5 project - these
are very useful for debugging.
diff --git a/Rakefile b/Rakefile
index f9019155..3221c7f2 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,5 +1,7 @@
#!/usr/bin/env ruby
+require "bundler/gem_tasks"
+require "salsify_gem"
require "rubygems"
require "rake/extensiontask"
require "rake/testtask"
@@ -7,7 +9,7 @@ require "rubygems/package_task"
require "rdoc/task"
require "yaml"
-GEM_NAME = "libxml-ruby"
+GEM_NAME = "salsify_libxml_ruby"
SO_NAME = "libxml_ruby"
# Read the spec file
@@ -88,4 +90,4 @@ Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList['test/test*.rb'] - ['test/test_suite.rb']
t.verbose = true
-end
\ No newline at end of file
+end
diff --git a/ext/libxml/extconf.rb b/ext/libxml/extconf.rb
index d047c1d6..ebfbc34c 100644
--- a/ext/libxml/extconf.rb
+++ b/ext/libxml/extconf.rb
@@ -2,56 +2,67 @@
require 'mkmf'
+LIBXML2_VERSION = '2.9.9'.freeze
+LIBXML2_SHA256 = '94fb70890143e3c6549f265cee93ec064c80a84c42ad0f23e85ee1fd6540a871'.freeze
+
+def darwin?
+ RbConfig::CONFIG['target_os'] =~ /darwin/
+end
+
def crash(str)
- printf(" extconf failure: %s\n", str)
+ puts(" extconf failure: #{str}")
exit 1
end
-xc = with_config('xml2-config')
-if xc
- cflags = `#{xc} --cflags`.chomp
- if $? != 0
- cflags = nil
- else
- libs = `#{xc} --libs`.chomp
- if $? != 0
- libs = nil
- else
- $CFLAGS += ' ' + cflags
- $libs = libs + " " + $libs
- end
- end
-else
- dir_config('xml2')
-end
+# The gem version constraint in the Rakefile is not respected at install time.
+# Keep this version in sync with the one in the Rakefile !
+require 'rubygems'
+gem 'mini_portile2', '~> 2.4.0'
+require 'mini_portile2'
+message "Using mini_portile version #{MiniPortile::VERSION}\n"
-unless find_header('libxml/xmlversion.h',
- '/opt/include/libxml2',
- '/opt/local/include/libxml2',
- '/usr/local/include/libxml2',
- '/usr/include/libxml2') &&
- find_library('xml2', 'xmlParseDoc',
- '/opt/lib',
- '/opt/local/lib',
- '/usr/local/lib',
- '/usr/lib')
- crash(<
Date: Wed, 17 Jul 2019 11:04:33 -0400
Subject: [PATCH 02/18] Fix iconv (#2)
* Only require iconv as a separate library on macOS
* Incremented gem version
---
Gemfile.lock | 27 +++++++++++++++++++++++++++
ext/libxml/extconf.rb | 6 ++++--
ext/libxml/ruby_xml_version.h | 6 +++---
3 files changed, 34 insertions(+), 5 deletions(-)
create mode 100644 Gemfile.lock
diff --git a/Gemfile.lock b/Gemfile.lock
new file mode 100644
index 00000000..11f9b51c
--- /dev/null
+++ b/Gemfile.lock
@@ -0,0 +1,27 @@
+PATH
+ remote: .
+ specs:
+ salsify_libxml_ruby (3.1.0)
+
+GEM
+ remote: https://gems.salsify.com/
+ specs:
+ minitest (5.11.3)
+ rake (12.3.2)
+ rake-compiler (1.0.7)
+ rake
+ salsify_gem (0.3.1)
+ thor
+ thor (0.20.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ minitest
+ rake-compiler
+ salsify_gem
+ salsify_libxml_ruby!
+
+BUNDLED WITH
+ 1.17.2
diff --git a/ext/libxml/extconf.rb b/ext/libxml/extconf.rb
index ebfbc34c..279d9233 100644
--- a/ext/libxml/extconf.rb
+++ b/ext/libxml/extconf.rb
@@ -21,9 +21,11 @@ def crash(str)
require 'mini_portile2'
message "Using mini_portile version #{MiniPortile::VERSION}\n"
-!darwin? || have_header('iconv.h') || crash('missing iconv.h')
+if darwin?
+ have_header('iconv.h') || crash('missing iconv.h')
+ have_library('iconv') || crash('missing libiconv')
+end
have_library('z', 'gzdopen', 'zlib.h') || crash('missing zlib')
-have_library('iconv') || crash('missing libiconv')
have_library('lzma') || crash('missing lzma')
libxml2_recipe = MiniPortile.new('libxml2', LIBXML2_VERSION)
diff --git a/ext/libxml/ruby_xml_version.h b/ext/libxml/ruby_xml_version.h
index 02ec80a4..13a6cfb6 100644
--- a/ext/libxml/ruby_xml_version.h
+++ b/ext/libxml/ruby_xml_version.h
@@ -1,9 +1,9 @@
/* Don't nuke this block! It is used for automatically updating the
* versions below. VERSION = string formatting, VERNUM = numbered
* version for inline testing: increment both or none at all.*/
-#define RUBY_LIBXML_VERSION "3.1.0"
-#define RUBY_LIBXML_VERNUM 310
+#define RUBY_LIBXML_VERSION "3.1.0.1"
+#define RUBY_LIBXML_VERNUM 3101
#define RUBY_LIBXML_VER_MAJ 3
#define RUBY_LIBXML_VER_MIN 1
#define RUBY_LIBXML_VER_MIC 0
-#define RUBY_LIBXML_VER_PATCH 0
+#define RUBY_LIBXML_VER_PATCH 1
From 8a7d20de392517f22bab35c8cd714590f5f414fe Mon Sep 17 00:00:00 2001
From: Radu Preotiuc <49693472+radupr@users.noreply.github.com>
Date: Wed, 17 Jul 2019 11:27:06 -0400
Subject: [PATCH 03/18] Deleted Gemfile.lock - added by mistake in previous
commit (#3)
---
Gemfile.lock | 27 ---------------------------
1 file changed, 27 deletions(-)
delete mode 100644 Gemfile.lock
diff --git a/Gemfile.lock b/Gemfile.lock
deleted file mode 100644
index 11f9b51c..00000000
--- a/Gemfile.lock
+++ /dev/null
@@ -1,27 +0,0 @@
-PATH
- remote: .
- specs:
- salsify_libxml_ruby (3.1.0)
-
-GEM
- remote: https://gems.salsify.com/
- specs:
- minitest (5.11.3)
- rake (12.3.2)
- rake-compiler (1.0.7)
- rake
- salsify_gem (0.3.1)
- thor
- thor (0.20.3)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- minitest
- rake-compiler
- salsify_gem
- salsify_libxml_ruby!
-
-BUNDLED WITH
- 1.17.2
From a27dfb1d910ea3d5248a192582f471a45b76e45d Mon Sep 17 00:00:00 2001
From: Radu Preotiuc <49693472+radupr@users.noreply.github.com>
Date: Wed, 17 Jul 2019 11:55:56 -0400
Subject: [PATCH 04/18] Correctly pass compilation flags that are needed on
Linux (#4)
* Correctly pass compilation flags neede on Linux
* Removed annnoying Gemfile.lock
---
ext/libxml/extconf.rb | 2 +-
ext/libxml/ruby_xml_version.h | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/ext/libxml/extconf.rb b/ext/libxml/extconf.rb
index 279d9233..ea300f15 100644
--- a/ext/libxml/extconf.rb
+++ b/ext/libxml/extconf.rb
@@ -48,7 +48,7 @@ def crash(str)
"--with-iconv",
*(darwin? ? ["RANLIB=/usr/bin/ranlib", "AR=/usr/bin/ar"] : "")
]
-append_cflags('-fPIC')
+env['CFLAGS'] = "-fPIC #{env['CFLAGS']}"
message "Building with libxml2-#{LIBXML2_VERSION}"
diff --git a/ext/libxml/ruby_xml_version.h b/ext/libxml/ruby_xml_version.h
index 13a6cfb6..2bc71526 100644
--- a/ext/libxml/ruby_xml_version.h
+++ b/ext/libxml/ruby_xml_version.h
@@ -1,9 +1,9 @@
/* Don't nuke this block! It is used for automatically updating the
* versions below. VERSION = string formatting, VERNUM = numbered
* version for inline testing: increment both or none at all.*/
-#define RUBY_LIBXML_VERSION "3.1.0.1"
-#define RUBY_LIBXML_VERNUM 3101
+#define RUBY_LIBXML_VERSION "3.1.0.2"
+#define RUBY_LIBXML_VERNUM 3102
#define RUBY_LIBXML_VER_MAJ 3
#define RUBY_LIBXML_VER_MIN 1
#define RUBY_LIBXML_VER_MIC 0
-#define RUBY_LIBXML_VER_PATCH 1
+#define RUBY_LIBXML_VER_PATCH 2
From 6b536434d507b9055f2fa8245a1057e9c03934f1 Mon Sep 17 00:00:00 2001
From: Radu Preotiuc <49693472+radupr@users.noreply.github.com>
Date: Wed, 17 Jul 2019 12:15:21 -0400
Subject: [PATCH 05/18] Fix access to environment variable (#5)
---
ext/libxml/extconf.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ext/libxml/extconf.rb b/ext/libxml/extconf.rb
index ea300f15..833fc63d 100644
--- a/ext/libxml/extconf.rb
+++ b/ext/libxml/extconf.rb
@@ -48,7 +48,7 @@ def crash(str)
"--with-iconv",
*(darwin? ? ["RANLIB=/usr/bin/ranlib", "AR=/usr/bin/ar"] : "")
]
-env['CFLAGS'] = "-fPIC #{env['CFLAGS']}"
+ENV['CFLAGS'] = "-fPIC #{ENV['CFLAGS']}"
message "Building with libxml2-#{LIBXML2_VERSION}"
From 244afe10a15008cedaa8aedb6855b2415703bf49 Mon Sep 17 00:00:00 2001
From: Radu Preotiuc
Date: Wed, 17 Jul 2019 12:17:23 -0400
Subject: [PATCH 06/18] Incremented version number
---
ext/libxml/ruby_xml_version.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/ext/libxml/ruby_xml_version.h b/ext/libxml/ruby_xml_version.h
index 2bc71526..adf8171f 100644
--- a/ext/libxml/ruby_xml_version.h
+++ b/ext/libxml/ruby_xml_version.h
@@ -1,9 +1,9 @@
/* Don't nuke this block! It is used for automatically updating the
* versions below. VERSION = string formatting, VERNUM = numbered
* version for inline testing: increment both or none at all.*/
-#define RUBY_LIBXML_VERSION "3.1.0.2"
-#define RUBY_LIBXML_VERNUM 3102
+#define RUBY_LIBXML_VERSION "3.1.0.3"
+#define RUBY_LIBXML_VERNUM 3103
#define RUBY_LIBXML_VER_MAJ 3
#define RUBY_LIBXML_VER_MIN 1
#define RUBY_LIBXML_VER_MIC 0
-#define RUBY_LIBXML_VER_PATCH 2
+#define RUBY_LIBXML_VER_PATCH 3
From 9a9c8273e4ab5369c6bd0a6a50c2532a7e8818c7 Mon Sep 17 00:00:00 2001
From: Radu Preotiuc
Date: Fri, 26 Jul 2019 15:27:21 -0400
Subject: [PATCH 07/18] Fixed field names in Schema::Element.
---
lib/libxml/schema/element.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/libxml/schema/element.rb b/lib/libxml/schema/element.rb
index 889d6252..fadf517f 100644
--- a/lib/libxml/schema/element.rb
+++ b/lib/libxml/schema/element.rb
@@ -4,11 +4,11 @@ module LibXML
module XML
class Schema::Element
def required?
- !min_occurs.zero?
+ !min.zero?
end
def array?
- max_occurs > 1
+ max > 1
end
def elements
From 159be3f61f4de47fbc145ade88778ac0563284cf Mon Sep 17 00:00:00 2001
From: Radu Preotiuc
Date: Fri, 26 Jul 2019 15:30:47 -0400
Subject: [PATCH 08/18] Fixed field names in Schema::Element.
---
ext/libxml/ruby_xml_version.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/ext/libxml/ruby_xml_version.h b/ext/libxml/ruby_xml_version.h
index adf8171f..74760f9d 100644
--- a/ext/libxml/ruby_xml_version.h
+++ b/ext/libxml/ruby_xml_version.h
@@ -1,9 +1,9 @@
/* Don't nuke this block! It is used for automatically updating the
* versions below. VERSION = string formatting, VERNUM = numbered
* version for inline testing: increment both or none at all.*/
-#define RUBY_LIBXML_VERSION "3.1.0.3"
-#define RUBY_LIBXML_VERNUM 3103
+#define RUBY_LIBXML_VERSION "3.1.0.4"
+#define RUBY_LIBXML_VERNUM 3104
#define RUBY_LIBXML_VER_MAJ 3
#define RUBY_LIBXML_VER_MIN 1
#define RUBY_LIBXML_VER_MIC 0
-#define RUBY_LIBXML_VER_PATCH 3
+#define RUBY_LIBXML_VER_PATCH 4
From 98bc20a792a8d980ff6e23fa8f1c458e215ad8d3 Mon Sep 17 00:00:00 2001
From: Radu Preotiuc
Date: Fri, 26 Jul 2019 15:40:15 -0400
Subject: [PATCH 09/18] Fixed field names in Schema::Element.
---
ext/libxml/ruby_xml_version.h | 6 +++---
lib/libxml/schema/element.rb | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/ext/libxml/ruby_xml_version.h b/ext/libxml/ruby_xml_version.h
index 74760f9d..b05fb8c0 100644
--- a/ext/libxml/ruby_xml_version.h
+++ b/ext/libxml/ruby_xml_version.h
@@ -1,9 +1,9 @@
/* Don't nuke this block! It is used for automatically updating the
* versions below. VERSION = string formatting, VERNUM = numbered
* version for inline testing: increment both or none at all.*/
-#define RUBY_LIBXML_VERSION "3.1.0.4"
-#define RUBY_LIBXML_VERNUM 3104
+#define RUBY_LIBXML_VERSION "3.1.0.5"
+#define RUBY_LIBXML_VERNUM 3105
#define RUBY_LIBXML_VER_MAJ 3
#define RUBY_LIBXML_VER_MIN 1
#define RUBY_LIBXML_VER_MIC 0
-#define RUBY_LIBXML_VER_PATCH 4
+#define RUBY_LIBXML_VER_PATCH 5
diff --git a/lib/libxml/schema/element.rb b/lib/libxml/schema/element.rb
index fadf517f..74b3acce 100644
--- a/lib/libxml/schema/element.rb
+++ b/lib/libxml/schema/element.rb
@@ -4,11 +4,11 @@ module LibXML
module XML
class Schema::Element
def required?
- !min.zero?
+ !@min.zero?
end
def array?
- max > 1
+ @max > 1
end
def elements
From 181467290bdaaa7844a6952c59b3fa2d34c040ac Mon Sep 17 00:00:00 2001
From: Radu Preotiuc
Date: Mon, 5 Aug 2019 11:12:51 -0400
Subject: [PATCH 10/18] One more fix for the max/minOccurs issue
---
ext/libxml/ruby_xml_version.h | 6 +++---
lib/libxml/schema/element.rb | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/ext/libxml/ruby_xml_version.h b/ext/libxml/ruby_xml_version.h
index b05fb8c0..b487b020 100644
--- a/ext/libxml/ruby_xml_version.h
+++ b/ext/libxml/ruby_xml_version.h
@@ -1,9 +1,9 @@
/* Don't nuke this block! It is used for automatically updating the
* versions below. VERSION = string formatting, VERNUM = numbered
* version for inline testing: increment both or none at all.*/
-#define RUBY_LIBXML_VERSION "3.1.0.5"
-#define RUBY_LIBXML_VERNUM 3105
+#define RUBY_LIBXML_VERSION "3.1.0.6"
+#define RUBY_LIBXML_VERNUM 3106
#define RUBY_LIBXML_VER_MAJ 3
#define RUBY_LIBXML_VER_MIN 1
#define RUBY_LIBXML_VER_MIC 0
-#define RUBY_LIBXML_VER_PATCH 5
+#define RUBY_LIBXML_VER_PATCH 6
diff --git a/lib/libxml/schema/element.rb b/lib/libxml/schema/element.rb
index 74b3acce..a295b6fb 100644
--- a/lib/libxml/schema/element.rb
+++ b/lib/libxml/schema/element.rb
@@ -4,11 +4,11 @@ module LibXML
module XML
class Schema::Element
def required?
- !@min.zero?
+ !@min || !@min.zero?
end
def array?
- @max > 1
+ @max && @max > 1
end
def elements
From 6b6bae3cf4d732a5b53e516301706a96e464ccc4 Mon Sep 17 00:00:00 2001
From: Radu Preotiuc <49693472+radupr@users.noreply.github.com>
Date: Mon, 26 Apr 2021 20:45:09 -0400
Subject: [PATCH 11/18] Merged changes. (#6)
---
HISTORY | 13 +
README.rdoc | 56 ++--
ext/libxml/extconf.rb | 1 -
ext/libxml/ruby_libxml.h | 8 -
ext/libxml/ruby_xml_document.c | 6 +-
ext/libxml/ruby_xml_dtd.c | 14 +-
ext/libxml/ruby_xml_encoding.c | 14 +-
ext/libxml/ruby_xml_encoding.h | 3 -
ext/libxml/ruby_xml_io.c | 32 +--
ext/libxml/ruby_xml_io.h | 2 +-
ext/libxml/ruby_xml_node.c | 2 +-
ext/libxml/ruby_xml_parser_context.c | 2 +-
ext/libxml/ruby_xml_version.h | 10 +-
ext/libxml/ruby_xml_writer.c | 381 ++++++++++++-------------
ext/vc/libxml_ruby/libxml_ruby.vcxproj | 18 +-
lib/libxml-ruby.rb | 30 ++
lib/libxml.rb | 31 +-
salsify_libxml_ruby.gemspec | 3 +-
test/test_attr.rb | 36 +--
test/test_attr_decl.rb | 16 +-
test/test_attributes.rb | 20 +-
test/test_canonicalize.rb | 40 ++-
test/test_deprecated_require.rb | 6 +-
test/test_document.rb | 50 ++--
test/test_document_write.rb | 127 +++------
test/test_dtd.rb | 46 +--
test/test_encoding.rb | 30 +-
test/test_encoding_sax.rb | 6 +-
test/test_error.rb | 102 +++----
test/test_helper.rb | 11 +-
test/test_html_parser.rb | 60 ++--
test/test_html_parser_context.rb | 12 +-
test/test_namespace.rb | 32 +--
test/test_namespaces.rb | 50 ++--
test/test_node.rb | 62 ++--
test/test_node_cdata.rb | 20 +-
test/test_node_comment.rb | 12 +-
test/test_node_copy.rb | 4 +-
test/test_node_edit.rb | 32 +--
test/test_node_pi.rb | 14 +-
test/test_node_text.rb | 12 +-
test/test_node_write.rb | 42 ++-
test/test_node_xlink.rb | 12 +-
test/test_parser.rb | 138 +++++----
test/test_parser_context.rb | 60 ++--
test/test_properties.rb | 10 +-
test/test_reader.rb | 165 ++++++-----
test/test_relaxng.rb | 22 +-
test/test_sax_parser.rb | 56 ++--
test/test_schema.rb | 48 ++--
test/test_suite.rb | 7 +-
test/test_traversal.rb | 8 +-
test/test_writer.rb | 169 ++++++-----
test/test_xinclude.rb | 6 +-
test/test_xml.rb | 214 +++++++-------
test/test_xpath.rb | 44 +--
test/test_xpath_context.rb | 10 +-
test/test_xpath_expression.rb | 12 +-
test/test_xpointer.rb | 30 +-
59 files changed, 1200 insertions(+), 1279 deletions(-)
create mode 100644 lib/libxml-ruby.rb
diff --git a/HISTORY b/HISTORY
index 75ce02f6..01add45b 100644
--- a/HISTORY
+++ b/HISTORY
@@ -1,5 +1,18 @@
= Release History
+== 3.2.1 / 2020-11-05
+
+* Fix incorrect handling of encodings when using XMLWriter.io (Charlie Savage)
+* Clean up README (Richard Michael)
+
+== 3.2.0 / 2020-05-09 Charlie Savage
+
+* Fix crash when creating an empty DTD
+* Modernize tests to use Bundler to load gem
+* Add libxml-ruby.rb file so gem loads in expected way.
+* Add support for xmlSaveNoEmptyTags.
+* Clean up extconf.rb file
+
== 3.1.0 / 2018-02-03 Charlie Savage
* Fix segmentation fault when adding one node to another node (Charlie Savage)
diff --git a/README.rdoc b/README.rdoc
index 4d1b93fe..f4cf5869 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -32,7 +32,7 @@ We think libxml-ruby is the best XML library for Ruby because:
The gem also includes a Microsoft VC++ 2012 solution and XCode 5 project - these
are very useful for debugging.
-libxml-ruby's source codes lives on Github at https://github.com/xml4r/libxml-ruby.
+libxml-ruby's source codes lives on GitHub[https://github.com/xml4r/libxml-ruby].
== Getting Started
Using libxml is easy. First decide what parser you want to use:
@@ -53,7 +53,7 @@ Beyond the basics of parsing and processing XML and HTML documents,
libxml provides a wealth of additional functionality.
Most commonly, you'll want to use its LibXML::XML::XPath support, which makes
-it easy to find data inside a XML document. Although not as popular,
+it easy to find data inside an XML document. Although not as popular,
LibXML::XML::XPointer provides another API for finding data inside an XML document.
Often times you'll need to validate data before processing it. For example,
@@ -65,17 +65,16 @@ This can be done using libxml's powerful set of validators:
* Relax Schemas (LibXML::XML::RelaxNG)
* XML Schema (LibXML::XML::Schema)
-Finally, if you'd like to use XSL Transformations to process data,
-then install the libxslt gem which is available at
-https://github.com/xml4r/libxslt-ruby.
+Finally, if you'd like to use XSL Transformations to process data, then install
+the {libxslt gem}[https://github.com/xml4r/libxslt-rubygem].
== Usage
-For information about using libxml-ruby please refer to its documentation at
-http://xml4r.github.com/libxml-ruby/rdoc/index.html. Some tutorials are also
-available at https://github.com/xml4r/libxml-ruby/wiki.
+For information about using libxml-ruby please refer to its
+documentation[http://xml4r.github.io/libxml-ruby]. Some tutorials are also
+available[https://github.com/xml4r/libxml-ruby/wiki].
All libxml classes are in the LibXML::XML module. The easiest
-way to use libxml is to require 'xml'. This will mixin
+way to use libxml is to require 'xml'. This will mixin
the LibXML module into the global namespace, allowing you to
write code like this:
@@ -124,10 +123,11 @@ Once you have build the shared libary, you can then run tests using rake:
+Travis build status: {}[https://travis-ci.org/xml4r/libxml-ruby]
== Performance
+
In addition to being feature rich and conformation, the main reason
-people use libxml-ruby is for performance. Here are the results
+people use libxml-ruby is for performance. Here are the results
of a couple simple benchmarks recently blogged about on the
-Web (you can find them in the benchmark directory of the
+Web (you can find them in the benchmark directory of the
libxml distribution).
From http://depixelate.com/2008/4/23/ruby-xml-parsing-benchmarks
@@ -149,46 +149,46 @@ From https://svn.concord.org/svn/projects/trunk/common/ruby/xml_benchmarks/
Documentation is available via rdoc, and is installed automatically with the
gem.
-libxml-ruby's online documentation is generated using Hanna, which is a
-development gem dependency.
+libxml-ruby's {online
+documentation}[https://xml4r.github.io/libxml-ruby/rdoc/index.html] is generated
+using Hanna, which is a development gem dependency.
Note that older versions of Rdoc, which ship with Ruby 1.8.x, will report
a number of errors. To avoid them, install Rdoc 2.1 or higher. Once you have
installed the gem, you'll have to disable the version of Rdoc that Ruby 1.8.x
-includes. An easy way to do that is rename the directory ruby/lib/ruby/1.8/rdoc to
-ruby/lib/ruby/1.8/rdoc_old.
+includes. An easy way to do that is rename the directory
+ruby/lib/ruby/1.8/rdoc to
+ruby/lib/ruby/1.8/rdoc_old.
== Support
-
-If you have any questions about using libxml-ruby, please report them to
-Git Hub at https://github.com/xml4r/libxml-ruby/issues
+If you have any questions about using libxml-ruby, please report an issue
+on GitHub[https://github.com/xml4r/libxml-ruby/issues].
== Memory Management
libxml-ruby automatically manages memory associated with the
underlying libxml2 library. The bindings create a one-to-one mapping between
-ruby objects and libxml documents and libxml parent nodes (ie, nodes that do not
-have a parent and do not belong to a document). In these cases,
+Ruby objects and libxml documents and libxml parent nodes (ie, nodes that do not
+have a parent and do not belong to a document). In these cases,
the bindings manage the memory. They do this by installing a free
function and storing a back pointer to the Ruby object from the xmlnode
using the _private member on libxml structures. When the Ruby object
goes out of scope, the underlying libxml structure is freed. Libxml
-itself then frees all child node (recursively).
+itself then frees all child nodes (recursively).
For all other nodes (the vast majority), the bindings create temporary
Ruby objects that get freed once they go out of scope. Thus there can be
-more than one ruby object pointing to the same xml node. To mostly hide
-this from programmers on the ruby side, the #eql? and #== methods are
-overriden to check if two ruby objects wrap the same xmlnode. If they do,
+more than one Ruby object pointing to the same xml node. To mostly hide
+this from a programmer on the Ruby side, the #eql? and #== methods are
+overriden to check if two Ruby objects wrap the same xmlnode. If they do,
then the methods return true. During the mark phase, each of these temporary
objects marks its owning document, thereby keeping the Ruby document object
alive and thus the xmldoc tree.
In the sweep phase of the garbage collector, or when a program ends,
-there is no order to how Ruby objects are freed. In fact, the ruby document
-object is almost always freed before any ruby objects that wrap child nodes.
-However, this is ok because those ruby objects do not have a free function
+there is no order to how Ruby objects are freed. In fact, the Ruby document
+object is almost always freed before any Ruby objects that wrap child nodes.
+However, this is ok because those Ruby objects do not have a free function
and are no longer in scope (since if they were the document would not be freed).
== License
See LICENSE for license information.
-
diff --git a/ext/libxml/extconf.rb b/ext/libxml/extconf.rb
index 833fc63d..bb349dcd 100644
--- a/ext/libxml/extconf.rb
+++ b/ext/libxml/extconf.rb
@@ -64,7 +64,6 @@ def crash(str)
have_header('libxml/parser.h') || crash('parser.h not found')
have_library('xml2', 'xmlParseDoc ') || crash('libxml2 not found')
-have_func('rb_io_bufwrite', 'ruby/io.h')
create_header()
create_makefile('libxml_ruby')
diff --git a/ext/libxml/ruby_libxml.h b/ext/libxml/ruby_libxml.h
index 3e90b931..a66b722f 100644
--- a/ext/libxml/ruby_libxml.h
+++ b/ext/libxml/ruby_libxml.h
@@ -16,15 +16,7 @@
#include
#include
-/* Needed prior to Ruby 1.9.1 */
-#ifndef RHASH_TBL
-#define RHASH_TBL(s) (RHASH(s)->tbl)
-#endif
-
-// Encoding support added in Ruby 1.9.*
-#ifdef HAVE_RUBY_ENCODING_H
#include
-#endif
#ifdef LIBXML_DEBUG_ENABLED
#include
diff --git a/ext/libxml/ruby_xml_document.c b/ext/libxml/ruby_xml_document.c
index e8826586..0dce1c1a 100644
--- a/ext/libxml/ruby_xml_document.c
+++ b/ext/libxml/ruby_xml_document.c
@@ -483,7 +483,6 @@ static VALUE rxml_document_encoding_get(VALUE self)
* Returns the Ruby encoding specified by this document
* (available on Ruby 1.9.x and higher).
*/
-#ifdef HAVE_RUBY_ENCODING_H
static VALUE rxml_document_rb_encoding_get(VALUE self)
{
xmlDocPtr xdoc;
@@ -493,7 +492,6 @@ static VALUE rxml_document_rb_encoding_get(VALUE self)
rbencoding = rxml_xml_encoding_to_rb_encoding(mXMLEncoding, xmlParseCharEncoding((const char*)xdoc->encoding));
return rb_enc_from_encoding(rbencoding);
}
-#endif
/*
* call-seq:
@@ -738,7 +736,7 @@ static VALUE rxml_document_root_set(VALUE self, VALUE node)
Data_Get_Struct(node, xmlNode, xnode);
if (xnode->doc != NULL && xnode->doc != xdoc)
- rb_raise(eXMLError, "Nodes belong to different documents. You must first import the node by calling XML::Document.import");
+ rb_raise(eXMLError, "Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import");
xmlDocSetRootElement(xdoc, xnode);
@@ -1097,9 +1095,7 @@ void rxml_init_document(void)
rb_define_method(cXMLDocument, "compression?", rxml_document_compression_q, 0);
rb_define_method(cXMLDocument, "debug", rxml_document_debug, 0);
rb_define_method(cXMLDocument, "encoding", rxml_document_encoding_get, 0);
-#ifdef HAVE_RUBY_ENCODING_H
rb_define_method(cXMLDocument, "rb_encoding", rxml_document_rb_encoding_get, 0);
-#endif
rb_define_method(cXMLDocument, "encoding=", rxml_document_encoding_set, 1);
rb_define_method(cXMLDocument, "import", rxml_document_import, 1);
rb_define_method(cXMLDocument, "last", rxml_document_last_get, 0);
diff --git a/ext/libxml/ruby_xml_dtd.c b/ext/libxml/ruby_xml_dtd.c
index 2cbc0dc8..062be1fe 100644
--- a/ext/libxml/ruby_xml_dtd.c
+++ b/ext/libxml/ruby_xml_dtd.c
@@ -38,13 +38,11 @@ void rxml_dtd_free(xmlDtdPtr xdtd)
void rxml_dtd_mark(xmlDtdPtr xdtd)
{
- VALUE doc = Qnil;
-
- if (xdtd == NULL)
- return;
-
- doc = (VALUE)xdtd->doc->_private;
- rb_gc_mark(doc);
+ if (xdtd && xdtd->doc)
+ {
+ VALUE doc = (VALUE)xdtd->doc->_private;
+ rb_gc_mark(doc);
+ }
}
static VALUE rxml_dtd_alloc(VALUE klass)
@@ -173,7 +171,7 @@ static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self)
}
if (doc != Qnil) {
if (rb_obj_is_kind_of(doc, cXMLDocument) == Qfalse)
- rb_raise(rb_eTypeError, "Must pass an XML::Document object");
+ rb_raise(rb_eTypeError, "Must pass an LibXML::XML::Document object");
Data_Get_Struct(doc, xmlDoc, xdoc);
}
diff --git a/ext/libxml/ruby_xml_encoding.c b/ext/libxml/ruby_xml_encoding.c
index 31e50eae..d53c8c64 100644
--- a/ext/libxml/ruby_xml_encoding.c
+++ b/ext/libxml/ruby_xml_encoding.c
@@ -74,7 +74,6 @@ static VALUE rxml_encoding_to_s(VALUE klass, VALUE encoding)
return rxml_new_cstr(xencoding, xencoding);
}
-#ifdef HAVE_RUBY_ENCODING_H
/*
* Converts an xmlCharEncoding enum value into a Ruby Encoding object (available
* on Ruby 1.9.* and higher).
@@ -179,26 +178,17 @@ rb_encoding* rxml_figure_encoding(const xmlChar* xencoding)
}
return result;
}
-#endif
VALUE rxml_new_cstr(const xmlChar* xstr, const xmlChar* xencoding)
{
-#ifdef HAVE_RUBY_ENCODING_H
rb_encoding *rbencoding = rxml_figure_encoding(xencoding);
return rb_external_str_new_with_enc((const char*)xstr, strlen((const char*)xstr), rbencoding);
-#else
- return rb_str_new2((const char*)xstr);
-#endif
}
VALUE rxml_new_cstr_len(const xmlChar* xstr, const long length, const xmlChar* xencoding)
{
-#ifdef HAVE_RUBY_ENCODING_H
rb_encoding *rbencoding = rxml_figure_encoding(xencoding);
return rb_external_str_new_with_enc((const char*)xstr, length, rbencoding);
-#else
- return rb_str_new((const char*)xstr, length);
-#endif
}
void rxml_init_encoding(void)
@@ -207,9 +197,7 @@ void rxml_init_encoding(void)
rb_define_module_function(mXMLEncoding, "from_s", rxml_encoding_from_s, 1);
rb_define_module_function(mXMLEncoding, "to_s", rxml_encoding_to_s, 1);
-#ifdef HAVE_RUBY_ENCODING_H
- // rb_define_module_function(mXMLEncoding, "to_rb_encoding", rxml_encoding_to_rb_encoding, 2);
-#endif
+ rb_define_module_function(mXMLEncoding, "to_rb_encoding", rxml_encoding_to_rb_encoding, 2);
/* -1: No char encoding detected. */
rb_define_const(mXMLEncoding, "ERROR", INT2NUM(XML_CHAR_ENCODING_ERROR));
diff --git a/ext/libxml/ruby_xml_encoding.h b/ext/libxml/ruby_xml_encoding.h
index cb582135..e0d89b46 100644
--- a/ext/libxml/ruby_xml_encoding.h
+++ b/ext/libxml/ruby_xml_encoding.h
@@ -7,13 +7,10 @@ extern VALUE mXMLEncoding;
void rxml_init_encoding();
-// Ruby 1.8/1.9 encoding compatibility
VALUE rxml_new_cstr(const xmlChar* xstr, const xmlChar* xencoding);
VALUE rxml_new_cstr_len(const xmlChar* xstr, const long length, const xmlChar* xencoding);
-#ifdef HAVE_RUBY_ENCODING_H
rb_encoding* rxml_xml_encoding_to_rb_encoding(VALUE klass, xmlCharEncoding xmlEncoding);
rb_encoding* rxml_figure_encoding(const xmlChar* xencoding);
-#endif
#endif
diff --git a/ext/libxml/ruby_xml_io.c b/ext/libxml/ruby_xml_io.c
index 465e70b6..e577a73f 100644
--- a/ext/libxml/ruby_xml_io.c
+++ b/ext/libxml/ruby_xml_io.c
@@ -1,13 +1,10 @@
/* Please see the LICENSE file for copyright and distribution information */
#include "ruby_libxml.h"
+#include
static ID READ_METHOD;
-#ifdef HAVE_RB_IO_BUFWRITE
-#include
-#else
static ID WRITE_METHOD;
-#endif /* !HAVE_RB_IO_BUFWRITE */
/* This method is called by libxml when it wants to read
more data from a stream. We go with the duck typing
@@ -27,25 +24,24 @@ int rxml_read_callback(void *context, char *buffer, int len)
return (int)size;
}
-int rxml_write_callback(void *context, const char *buffer, int len)
+int rxml_write_callback(VALUE io, const char *buffer, int len)
{
-#ifndef HAVE_RB_IO_BUFWRITE
- VALUE io, written, string;
-
- io = (VALUE) context;
- string = rb_str_new(buffer, len);
- written = rb_funcall(io, WRITE_METHOD, 1, string);
-
- return NUM2INT(written);
-#else
- return (int)rb_io_bufwrite((VALUE) context, buffer, (size_t)len);
-#endif /* !HAVE_RB_IO_BUFWRITE */
+ if (rb_io_check_io(io) == Qnil)
+ {
+ // Could be StringIO
+ VALUE written, string;
+ string = rb_external_str_new_with_enc(buffer, strlen(buffer), rb_enc_get(io));
+ written = rb_funcall(io, WRITE_METHOD, 1, string);
+ return NUM2INT(written);
+ }
+ else
+ {
+ return (int)rb_io_bufwrite(io, buffer, (size_t)len);
+ }
}
void rxml_init_io(void)
{
READ_METHOD = rb_intern("read");
-#ifndef HAVE_RB_IO_BUFWRITE
WRITE_METHOD = rb_intern("write");
-#endif /* !HAVE_RB_IO_BUFWRITE */
}
diff --git a/ext/libxml/ruby_xml_io.h b/ext/libxml/ruby_xml_io.h
index 7e8a0fc0..cafd95ce 100644
--- a/ext/libxml/ruby_xml_io.h
+++ b/ext/libxml/ruby_xml_io.h
@@ -4,7 +4,7 @@
#define __RXML_IO__
int rxml_read_callback(void *context, char *buffer, int len);
-int rxml_write_callback(void *context, const char *buffer, int len);
+int rxml_write_callback(VALUE io, const char *buffer, int len);
void rxml_init_io(void);
#endif
diff --git a/ext/libxml/ruby_xml_node.c b/ext/libxml/ruby_xml_node.c
index 4d20c9a1..0f2b9d37 100644
--- a/ext/libxml/ruby_xml_node.c
+++ b/ext/libxml/ruby_xml_node.c
@@ -310,7 +310,7 @@ static VALUE rxml_node_modify_dom(VALUE self, VALUE target,
xtarget = rxml_get_xnode(target);
if (xtarget->doc != NULL && xtarget->doc != xnode->doc)
- rb_raise(eXMLError, "Nodes belong to different documents. You must first import the node by calling XML::Document.import");
+ rb_raise(eXMLError, "Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import");
xmlUnlinkNode(xtarget);
diff --git a/ext/libxml/ruby_xml_parser_context.c b/ext/libxml/ruby_xml_parser_context.c
index e679e526..e9f7a04e 100644
--- a/ext/libxml/ruby_xml_parser_context.c
+++ b/ext/libxml/ruby_xml_parser_context.c
@@ -47,7 +47,7 @@ static VALUE rxml_parser_context_document(VALUE klass, VALUE document)
int length;
if (rb_obj_is_kind_of(document, cXMLDocument) == Qfalse)
- rb_raise(rb_eTypeError, "Must pass an XML::Document object");
+ rb_raise(rb_eTypeError, "Must pass an LibXML::XML::Document object");
Data_Get_Struct(document, xmlDoc, xdoc);
xmlDocDumpFormatMemoryEnc(xdoc, &buffer, &length, (const char*)xdoc->encoding, 0);
diff --git a/ext/libxml/ruby_xml_version.h b/ext/libxml/ruby_xml_version.h
index b487b020..63e5b019 100644
--- a/ext/libxml/ruby_xml_version.h
+++ b/ext/libxml/ruby_xml_version.h
@@ -1,9 +1,9 @@
/* Don't nuke this block! It is used for automatically updating the
* versions below. VERSION = string formatting, VERNUM = numbered
* version for inline testing: increment both or none at all.*/
-#define RUBY_LIBXML_VERSION "3.1.0.6"
-#define RUBY_LIBXML_VERNUM 3106
+#define RUBY_LIBXML_VERSION "3.2.1.1"
+#define RUBY_LIBXML_VERNUM 3211
#define RUBY_LIBXML_VER_MAJ 3
-#define RUBY_LIBXML_VER_MIN 1
-#define RUBY_LIBXML_VER_MIC 0
-#define RUBY_LIBXML_VER_PATCH 6
+#define RUBY_LIBXML_VER_MIN 2
+#define RUBY_LIBXML_VER_MIC 1
+#define RUBY_LIBXML_VER_PATCH 1
diff --git a/ext/libxml/ruby_xml_writer.c b/ext/libxml/ruby_xml_writer.c
index a385484b..68a706ef 100644
--- a/ext/libxml/ruby_xml_writer.c
+++ b/ext/libxml/ruby_xml_writer.c
@@ -19,57 +19,29 @@ static VALUE sEncoding, sStandalone;
#include
-typedef enum {
+typedef enum
+{
RXMLW_OUTPUT_NONE,
RXMLW_OUTPUT_IO,
RXMLW_OUTPUT_DOC,
RXMLW_OUTPUT_STRING
} rxmlw_output_type;
-typedef struct {
+typedef struct
+{
VALUE output;
-#ifdef HAVE_RUBY_ENCODING_H
- rb_encoding *encoding;
-#endif /* HAVE_RUBY_ENCODING_H */
+ rb_encoding* encoding;
xmlBufferPtr buffer;
xmlTextWriterPtr writer;
rxmlw_output_type output_type;
int closed;
} rxml_writer_object;
-#ifdef HAVE_RUBY_ENCODING_H
-
-#define /*VALUE*/ rxml_writer_c_to_ruby_string(/*const xmlChar **/ string, /*long*/ string_len) \
- rb_external_str_new_with_enc(string, string_len, rb_utf8_encoding())
-
-#define /*VALUE*/ rxml_writer_ruby_string_to_utf8(/*VALUE*/ string) \
- rb_str_conv_enc(string, rb_enc_get(string), rb_utf8_encoding())
-// rb_str_export_to_enc(string, rb_utf8_encoding())
-
-#define /*void*/ rxml_writer_free_utf8_string(/*VALUE*/ orig, /*VALUE*/ utf8) \
- do { \
- if (orig != utf8) { \
- rb_str_free(utf8); \
- } \
- } while (0);
-
-#else
-
-#define /*VALUE*/ rxml_writer_c_to_ruby_string(/*const xmlChar **/ string, /*long*/ string_len) \
- rb_str_new(string, string_len)
-
-#define /*VALUE*/ rxml_writer_ruby_string_to_utf8(/*VALUE*/ string) \
- string
-
-#define /*void*/ rxml_writer_free_utf8_string(/*VALUE*/ orig, /*VALUE*/ utf8) \
- /* NOP */
-
-#endif /* HAVE_RUBY_ENCODING_H */
-
-static void rxml_writer_free(rxml_writer_object *rwo)
+static void rxml_writer_free(rxml_writer_object* rwo)
{
#if 0 /* seems to be done by xmlFreeTextWriter */
- if (NULL != rwo->buffer) {
+ if (NULL != rwo->buffer)
+ {
xmlBufferFree(rwo->buffer);
}
#endif
@@ -79,36 +51,40 @@ static void rxml_writer_free(rxml_writer_object *rwo)
xfree(rwo);
}
-static void rxml_writer_mark(rxml_writer_object *rwo)
+static void rxml_writer_mark(rxml_writer_object* rwo)
{
- if (!NIL_P(rwo->output)) {
+ if (!NIL_P(rwo->output))
+ {
rb_gc_mark(rwo->output);
}
}
-static VALUE rxml_writer_wrap(rxml_writer_object *rwo)
+static VALUE rxml_writer_wrap(rxml_writer_object* rwo)
{
return Data_Wrap_Struct(cXMLWriter, rxml_writer_mark, rxml_writer_free, rwo);
}
-static rxml_writer_object *rxml_textwriter_get(VALUE obj)
+static rxml_writer_object* rxml_textwriter_get(VALUE obj)
{
- rxml_writer_object *rwo;
+ rxml_writer_object* rwo;
Data_Get_Struct(obj, rxml_writer_object, rwo);
return rwo;
}
-int rxml_writer_write_callback(void *context, const char *buffer, int len)
+int rxml_writer_write_callback(void* context, const char* buffer, int len)
{
- rxml_writer_object *rwo = context;
+ rxml_writer_object* rwo = context;
- if(rwo->closed){
- return 0;
- }else{
- return rxml_write_callback((void *)rwo->output, buffer, len);
- }
+ if (rwo->closed)
+ {
+ return 0;
+ }
+ else
+ {
+ return rxml_write_callback(rwo->output, buffer, len);
+ }
}
/* ===== public class methods ===== */
@@ -120,31 +96,26 @@ int rxml_writer_write_callback(void *context, const char *buffer, int len)
*/
static VALUE rxml_writer_io(VALUE klass, VALUE io)
{
-#if 0
-typedef int (*xmlOutputCloseCallback)(void * context);
-typedef int (*xmlOutputWriteCallback)(void * context, const char * buffer, int len);
-
-ssize_t rb_io_bufwrite(VALUE io, const void *buf, size_t size);
-
-xmlOutputBufferPtr xmlOutputBufferCreateIO(xmlOutputWriteCallback iowrite, xmlOutputCloseCallback ioclose, void * ioctx, xmlCharEncodingHandlerPtr encoder)
-
-xmlCharEncodingHandlerPtr xmlFindCharEncodingHandler(const char * name);
-#endif
xmlOutputBufferPtr out;
- rxml_writer_object *rwo;
+ rxml_writer_object* rwo;
rwo = ALLOC(rxml_writer_object);
rwo->output = io;
rwo->buffer = NULL;
rwo->closed = 0;
-#ifdef HAVE_RUBY_ENCODING_H
- rwo->encoding = NULL;
-#endif /* HAVE_RUBY_ENCODING_H */
+ rwo->encoding = rb_enc_get(io);
+ if (!rwo->encoding)
+ rwo->encoding = rb_utf8_encoding();
+
rwo->output_type = RXMLW_OUTPUT_IO;
- if (NULL == (out = xmlOutputBufferCreateIO(rxml_writer_write_callback, NULL, (void *) rwo, NULL))) {
+
+ xmlCharEncodingHandlerPtr encodingHdlr = xmlFindCharEncodingHandler(rwo->encoding->name);
+ if (NULL == (out = xmlOutputBufferCreateIO(rxml_writer_write_callback, NULL, (void*)rwo, encodingHdlr)))
+ {
rxml_raise(&xmlLastError);
}
- if (NULL == (rwo->writer = xmlNewTextWriter(out))) {
+ if (NULL == (rwo->writer = xmlNewTextWriter(out)))
+ {
rxml_raise(&xmlLastError);
}
@@ -160,17 +131,16 @@ xmlCharEncodingHandlerPtr xmlFindCharEncodingHandler(const char * name);
*/
static VALUE rxml_writer_file(VALUE klass, VALUE filename)
{
- rxml_writer_object *rwo;
+ rxml_writer_object* rwo;
rwo = ALLOC(rxml_writer_object);
rwo->output = Qnil;
rwo->buffer = NULL;
rwo->closed = 0;
-#ifdef HAVE_RUBY_ENCODING_H
- rwo->encoding = NULL;
-#endif /* HAVE_RUBY_ENCODING_H */
+ rwo->encoding = rb_utf8_encoding();
rwo->output_type = RXMLW_OUTPUT_NONE;
- if (NULL == (rwo->writer = xmlNewTextWriterFilename(StringValueCStr(filename), 0))) {
+ if (NULL == (rwo->writer = xmlNewTextWriterFilename(StringValueCStr(filename), 0)))
+ {
rxml_raise(&xmlLastError);
}
@@ -184,19 +154,19 @@ static VALUE rxml_writer_file(VALUE klass, VALUE filename)
*/
static VALUE rxml_writer_string(VALUE klass)
{
- rxml_writer_object *rwo;
+ rxml_writer_object* rwo;
rwo = ALLOC(rxml_writer_object);
rwo->output = Qnil;
rwo->closed = 0;
-#ifdef HAVE_RUBY_ENCODING_H
- rwo->encoding = NULL;
-#endif /* HAVE_RUBY_ENCODING_H */
+ rwo->encoding = rb_utf8_encoding();
rwo->output_type = RXMLW_OUTPUT_STRING;
- if (NULL == (rwo->buffer = xmlBufferCreate())) {
+ if (NULL == (rwo->buffer = xmlBufferCreate()))
+ {
rxml_raise(&xmlLastError);
}
- if (NULL == (rwo->writer = xmlNewTextWriterMemory(rwo->buffer, 0))) {
+ if (NULL == (rwo->writer = xmlNewTextWriterMemory(rwo->buffer, 0)))
+ {
xmlBufferFree(rwo->buffer);
rxml_raise(&xmlLastError);
}
@@ -212,17 +182,16 @@ static VALUE rxml_writer_string(VALUE klass)
static VALUE rxml_writer_doc(VALUE klass)
{
xmlDocPtr doc;
- rxml_writer_object *rwo;
+ rxml_writer_object* rwo;
rwo = ALLOC(rxml_writer_object);
rwo->buffer = NULL;
rwo->output = Qnil;
rwo->closed = 0;
-#ifdef HAVE_RUBY_ENCODING_H
- rwo->encoding = NULL;
-#endif /* HAVE_RUBY_ENCODING_H */
+ rwo->encoding = rb_utf8_encoding();
rwo->output_type = RXMLW_OUTPUT_DOC;
- if (NULL == (rwo->writer = xmlNewTextWriterDoc(&doc, 0))) {
+ if (NULL == (rwo->writer = xmlNewTextWriterDoc(&doc, 0)))
+ {
rxml_raise(&xmlLastError);
}
rwo->output = rxml_document_wrap(doc);
@@ -240,33 +209,34 @@ static VALUE rxml_writer_doc(VALUE klass)
* If +empty?+ is +true+, and for a in memory XML::Writer, this internel
* buffer is empty.
*/
-static VALUE rxml_writer_flush(int argc, VALUE *argv, VALUE self)
+static VALUE rxml_writer_flush(int argc, VALUE* argv, VALUE self)
{
int ret;
VALUE empty;
- rxml_writer_object *rwo;
+ rxml_writer_object* rwo;
rb_scan_args(argc, argv, "01", &empty);
rwo = rxml_textwriter_get(self);
- if (-1 == (ret = xmlTextWriterFlush(rwo->writer))) {
+ if (-1 == (ret = xmlTextWriterFlush(rwo->writer)))
+ {
rxml_raise(&xmlLastError);
}
- if (NULL != rwo->buffer) {
+ if (NULL != rwo->buffer)
+ {
VALUE content;
-#ifdef HAVE_RUBY_ENCODING_H
content = rb_external_str_new_with_enc((const char*)rwo->buffer->content, rwo->buffer->use, rwo->encoding);
-#else
- content = rb_str_new(rwo->buffer->content, rwo->buffer->use);
-#endif /* HAVE_RUBY_ENCODING_H */
- if (NIL_P(empty) || RTEST(empty)) { /* nil = default value = true */
+ if (NIL_P(empty) || RTEST(empty))
+ { /* nil = default value = true */
xmlBufferEmpty(rwo->buffer);
}
return content;
- } else {
+ }
+ else
+ {
return INT2NUM(ret);
}
}
@@ -281,26 +251,28 @@ static VALUE rxml_writer_flush(int argc, VALUE *argv, VALUE self)
static VALUE rxml_writer_result(VALUE self)
{
VALUE ret = Qnil;
- rxml_writer_object *rwo = rxml_textwriter_get(self);
+ rxml_writer_object* rwo = rxml_textwriter_get(self);
int bytesWritten = xmlTextWriterFlush(rwo->writer);
- if (bytesWritten == -1) {
+ if (bytesWritten == -1)
+ {
rxml_raise(&xmlLastError);
}
- switch (rwo->output_type) {
- case RXMLW_OUTPUT_DOC:
- ret = rwo->output;
- break;
- case RXMLW_OUTPUT_STRING:
- ret = rxml_writer_c_to_ruby_string((const char*)rwo->buffer->content, rwo->buffer->use);
- break;
- case RXMLW_OUTPUT_IO:
- case RXMLW_OUTPUT_NONE:
- break;
- default:
- rb_bug("unexpected output");
- break;
+ switch (rwo->output_type)
+ {
+ case RXMLW_OUTPUT_DOC:
+ ret = rwo->output;
+ break;
+ case RXMLW_OUTPUT_STRING:
+ ret = rb_external_str_new_with_enc((const char*)rwo->buffer->content, rwo->buffer->use, rwo->encoding);
+ break;
+ case RXMLW_OUTPUT_IO:
+ case RXMLW_OUTPUT_NONE:
+ break;
+ default:
+ rb_bug("unexpected output");
+ break;
}
return ret;
@@ -311,7 +283,7 @@ static VALUE rxml_writer_result(VALUE self)
static VALUE numeric_rxml_writer_void(VALUE obj, int (*fn)(xmlTextWriterPtr))
{
int ret;
- rxml_writer_object *rwo;
+ rxml_writer_object* rwo;
rwo = rxml_textwriter_get(obj);
ret = fn(rwo->writer);
@@ -335,88 +307,102 @@ static VALUE numeric_rxml_writer_va_strings(VALUE obj, VALUE pe, size_t strings_
{
va_list ap;
size_t argc;
- int ret = -1;
- rxml_writer_object *rwo;
- const xmlChar *argv[XMLWRITER_MAX_STRING_ARGS];
+ int ret = -1;
+ rxml_writer_object* rwo;
+ const xmlChar* argv[XMLWRITER_MAX_STRING_ARGS];
VALUE utf8[XMLWRITER_MAX_STRING_ARGS], orig[XMLWRITER_MAX_STRING_ARGS];
- if (strings_count > XMLWRITER_MAX_STRING_ARGS) {
+ if (strings_count > XMLWRITER_MAX_STRING_ARGS)
+ {
rb_bug("more arguments than expected");
}
va_start(ap, fn);
rwo = rxml_textwriter_get(obj);
- for (argc = 0; argc < strings_count; argc++) {
+ for (argc = 0; argc < strings_count; argc++)
+ {
VALUE arg;
arg = va_arg(ap, VALUE);
orig[argc] = arg;
- if (NIL_P(arg)) {
+ if (NIL_P(arg))
+ {
utf8[argc] = Qnil;
argv[argc] = NULL;
- } else {
- utf8[argc] = rxml_writer_ruby_string_to_utf8(orig[argc]);
+ }
+ else
+ {
+ utf8[argc] = rb_str_conv_enc(orig[argc], rb_enc_get(orig[argc]), rwo->encoding);
argv[argc] = BAD_CAST StringValueCStr(utf8[argc]);
}
}
va_end(ap);
- if (Qundef == pe) {
- switch (strings_count) {
- case 0:
- ret = fn(rwo->writer);
- break;
- case 1:
- ret = fn(rwo->writer, argv[0]);
- break;
- case 2:
- ret = fn(rwo->writer, argv[0], argv[1]);
- break;
- case 3:
- ret = fn(rwo->writer, argv[0], argv[1], argv[2]);
- break;
- case 4:
- ret = fn(rwo->writer, argv[0], argv[1], argv[2], argv[3]);
- break;
- case 5:
- ret = fn(rwo->writer, argv[0], argv[1], argv[2], argv[3], argv[4]);
- break;
- default:
- break;
+ if (Qundef == pe)
+ {
+ switch (strings_count)
+ {
+ case 0:
+ ret = fn(rwo->writer);
+ break;
+ case 1:
+ ret = fn(rwo->writer, argv[0]);
+ break;
+ case 2:
+ ret = fn(rwo->writer, argv[0], argv[1]);
+ break;
+ case 3:
+ ret = fn(rwo->writer, argv[0], argv[1], argv[2]);
+ break;
+ case 4:
+ ret = fn(rwo->writer, argv[0], argv[1], argv[2], argv[3]);
+ break;
+ case 5:
+ ret = fn(rwo->writer, argv[0], argv[1], argv[2], argv[3], argv[4]);
+ break;
+ default:
+ break;
}
- } else {
+ }
+ else
+ {
int xpe;
xpe = RTEST(pe);
- switch (strings_count) { /* strings_count doesn't include pe */
- case 0:
- ret = fn(rwo->writer, xpe);
- break;
- case 1:
- ret = fn(rwo->writer, xpe, argv[0]);
- break;
- case 2:
- ret = fn(rwo->writer, xpe, argv[0], argv[1]);
- break;
- case 3:
- ret = fn(rwo->writer, xpe, argv[0], argv[1], argv[2]);
- break;
- case 4:
- ret = fn(rwo->writer, xpe, argv[0], argv[1], argv[2], argv[3]);
- break;
- case 5:
- ret = fn(rwo->writer, xpe, argv[0], argv[1], argv[2], argv[3], argv[4]);
- break;
- default:
- break;
+ switch (strings_count)
+ { /* strings_count doesn't include pe */
+ case 0:
+ ret = fn(rwo->writer, xpe);
+ break;
+ case 1:
+ ret = fn(rwo->writer, xpe, argv[0]);
+ break;
+ case 2:
+ ret = fn(rwo->writer, xpe, argv[0], argv[1]);
+ break;
+ case 3:
+ ret = fn(rwo->writer, xpe, argv[0], argv[1], argv[2]);
+ break;
+ case 4:
+ ret = fn(rwo->writer, xpe, argv[0], argv[1], argv[2], argv[3]);
+ break;
+ case 5:
+ ret = fn(rwo->writer, xpe, argv[0], argv[1], argv[2], argv[3], argv[4]);
+ break;
+ default:
+ break;
}
}
-#ifdef HAVE_RUBY_ENCODING_H
- while (--strings_count > 0) {
- if (!NIL_P(orig[strings_count])) {
- rxml_writer_free_utf8_string(orig[strings_count], utf8[strings_count]);
+
+ while (--strings_count > 0)
+ {
+ if (!NIL_P(orig[strings_count]))
+ {
+ if (orig[strings_count] != utf8[strings_count])
+ {
+ rb_str_free(utf8[strings_count]);
+ }
}
}
-#endif /* HAVE_RUBY_ENCODING_H */
return (-1 == ret ? Qfalse : Qtrue);
}
@@ -434,7 +420,7 @@ static VALUE numeric_rxml_writer_va_strings(VALUE obj, VALUE pe, size_t strings_
static VALUE rxml_writer_set_indent(VALUE self, VALUE indentation)
{
int ret;
- rxml_writer_object *rwo;
+ rxml_writer_object* rwo;
rwo = rxml_textwriter_get(self);
ret = xmlTextWriterSetIndent(rwo->writer, RTEST(indentation));
@@ -484,7 +470,7 @@ static VALUE rxml_writer_write_cdata(VALUE self, VALUE content)
}
static VALUE rxml_writer_start_element(VALUE, VALUE);
-static VALUE rxml_writer_start_element_ns(int, VALUE *, VALUE);
+static VALUE rxml_writer_start_element_ns(int, VALUE*, VALUE);
static VALUE rxml_writer_end_element(VALUE);
/* call-seq:
@@ -494,17 +480,21 @@ static VALUE rxml_writer_end_element(VALUE);
* This is equivalent to start_element(name) + write_string(content) +
* end_element.
*/
-static VALUE rxml_writer_write_element(int argc, VALUE *argv, VALUE self)
+static VALUE rxml_writer_write_element(int argc, VALUE* argv, VALUE self)
{
VALUE name, content;
rb_scan_args(argc, argv, "11", &name, &content);
- if (Qnil == content) {
- if (Qfalse == rxml_writer_start_element(self, name)) {
+ if (Qnil == content)
+ {
+ if (Qfalse == rxml_writer_start_element(self, name))
+ {
return Qfalse;
}
return rxml_writer_end_element(self);
- } else {
+ }
+ else
+ {
return numeric_rxml_writer_va_strings(self, Qundef, 2, xmlTextWriterWriteElement, name, content);
}
}
@@ -526,19 +516,23 @@ static VALUE rxml_writer_write_element(int argc, VALUE *argv, VALUE self)
* earlier.
* - +content+ can be omitted for an empty tag
*/
-static VALUE rxml_writer_write_element_ns(int argc, VALUE *argv, VALUE self)
+static VALUE rxml_writer_write_element_ns(int argc, VALUE* argv, VALUE self)
{
VALUE prefix, name, namespaceURI, content;
rb_scan_args(argc, argv, "22", &prefix, &name, &namespaceURI, &content);
- if (Qnil == content) {
+ if (Qnil == content)
+ {
VALUE argv[3] = { prefix, name, namespaceURI };
- if (Qfalse == rxml_writer_start_element_ns(ARRAY_SIZE(argv), argv, self)) {
+ if (Qfalse == rxml_writer_start_element_ns(ARRAY_SIZE(argv), argv, self))
+ {
return Qfalse;
}
return rxml_writer_end_element(self);
- } else {
+ }
+ else
+ {
return numeric_rxml_writer_va_strings(self, Qundef, 4, xmlTextWriterWriteElementNS, prefix, name, namespaceURI, content);
}
}
@@ -568,7 +562,7 @@ static VALUE rxml_writer_write_attribute(VALUE self, VALUE name, VALUE content)
* earlier.
* - +content+ can be omitted too for an empty attribute
*/
-static VALUE rxml_writer_write_attribute_ns(int argc, VALUE *argv, VALUE self)
+static VALUE rxml_writer_write_attribute_ns(int argc, VALUE* argv, VALUE self)
{
VALUE prefix, name, namespaceURI, content;
@@ -634,7 +628,7 @@ static VALUE rxml_writer_start_attribute(VALUE self, VALUE name)
* +namespaceURI+ to nil or omit it. Don't forget to declare the namespace
* prefix somewhere earlier.
*/
-static VALUE rxml_writer_start_attribute_ns(int argc, VALUE *argv, VALUE self)
+static VALUE rxml_writer_start_attribute_ns(int argc, VALUE* argv, VALUE self)
{
VALUE prefix, name, namespaceURI;
@@ -697,7 +691,7 @@ static VALUE rxml_writer_start_element(VALUE self, VALUE name)
* +namespaceURI+ to nil or omit it. Don't forget to declare the namespace
* prefix somewhere earlier.
*/
-static VALUE rxml_writer_start_element_ns(int argc, VALUE *argv, VALUE self)
+static VALUE rxml_writer_start_element_ns(int argc, VALUE* argv, VALUE self)
{
VALUE prefix, name, namespaceURI;
@@ -762,16 +756,17 @@ static VALUE rxml_writer_end_cdata(VALUE self)
* - standalone: nil (default) or a boolean to indicate if the document is
* standalone or not
*/
-static VALUE rxml_writer_start_document(int argc, VALUE *argv, VALUE self)
+static VALUE rxml_writer_start_document(int argc, VALUE* argv, VALUE self)
{
int ret;
VALUE options = Qnil;
- rxml_writer_object *rwo;
- const xmlChar *xencoding = NULL;
- const char *xstandalone = NULL;
+ rxml_writer_object* rwo;
+ const xmlChar* xencoding = NULL;
+ const char* xstandalone = NULL;
rb_scan_args(argc, argv, "01", &options);
- if (!NIL_P(options)) {
+ if (!NIL_P(options))
+ {
VALUE encoding, standalone;
encoding = standalone = Qnil;
@@ -779,16 +774,17 @@ static VALUE rxml_writer_start_document(int argc, VALUE *argv, VALUE self)
encoding = rb_hash_aref(options, sEncoding);
xencoding = NIL_P(encoding) ? NULL : (const xmlChar*)xmlGetCharEncodingName(NUM2INT(encoding));
standalone = rb_hash_aref(options, sStandalone);
- if (NIL_P(standalone)) {
+ if (NIL_P(standalone))
+ {
xstandalone = NULL;
- } else {
+ }
+ else
+ {
xstandalone = RTEST(standalone) ? "yes" : "no";
}
}
rwo = rxml_textwriter_get(self);
-#ifdef HAVE_RUBY_ENCODING_H
rwo->encoding = rxml_figure_encoding(xencoding);
-#endif /* !HAVE_RUBY_ENCODING_H */
ret = xmlTextWriterStartDocument(rwo->writer, NULL, (const char*)xencoding, xstandalone);
return (-1 == ret ? Qfalse : Qtrue);
@@ -829,7 +825,7 @@ static VALUE rxml_writer_end_pi(VALUE self)
*
* Starts a DTD. Returns +false+ on failure.
*/
-static VALUE rxml_writer_start_dtd(int argc, VALUE *argv, VALUE self)
+static VALUE rxml_writer_start_dtd(int argc, VALUE* argv, VALUE self)
{
VALUE name, pubid, sysid;
@@ -853,12 +849,13 @@ static VALUE rxml_writer_start_dtd_element(VALUE self, VALUE name)
*
* Starts a DTD entity (). Returns +false+ on failure.
*/
-static VALUE rxml_writer_start_dtd_entity(int argc, VALUE *argv, VALUE self)
+static VALUE rxml_writer_start_dtd_entity(int argc, VALUE* argv, VALUE self)
{
VALUE name, pe;
rb_scan_args(argc, argv, "11", &name, &pe);
- if (NIL_P(pe)) {
+ if (NIL_P(pe))
+ {
pe = Qfalse;
}
@@ -934,7 +931,7 @@ static VALUE rxml_writer_end_dtd_element(VALUE self)
* writer.write_dtd 'person', nil, nil, ''
* #=> ]>
*/
-static VALUE rxml_writer_write_dtd(int argc, VALUE *argv, VALUE self)
+static VALUE rxml_writer_write_dtd(int argc, VALUE* argv, VALUE self)
{
VALUE name, pubid, sysid, subset;
@@ -1043,12 +1040,12 @@ static VALUE rxml_writer_write_dtd_notation(VALUE self, VALUE name, VALUE pubid,
static VALUE rxml_writer_set_quote_char(VALUE self, VALUE quotechar)
{
int ret;
- const char *xquotechar;
- rxml_writer_object *rwo;
+ const char* xquotechar;
+ rxml_writer_object* rwo;
rwo = rxml_textwriter_get(self);
xquotechar = StringValueCStr(quotechar);
- ret = xmlTextWriterSetQuoteChar(rwo->writer, (xmlChar) xquotechar[0]);
+ ret = xmlTextWriterSetQuoteChar(rwo->writer, (xmlChar)xquotechar[0]);
return (-1 == ret ? Qfalse : Qtrue);
}
diff --git a/ext/vc/libxml_ruby/libxml_ruby.vcxproj b/ext/vc/libxml_ruby/libxml_ruby.vcxproj
index f0a9e000..226ef25a 100644
--- a/ext/vc/libxml_ruby/libxml_ruby.vcxproj
+++ b/ext/vc/libxml_ruby/libxml_ruby.vcxproj
@@ -22,30 +22,30 @@
{0B65CD1D-EEB9-41AE-93BB-75496E504152}libxmlWin32Proj
- 10.0.16299.0
+ 10.0DynamicLibraryUnicodetrue
- v141
+ v142DynamicLibraryUnicodetrue
- v141
+ v142DynamicLibraryUnicode
- v141
+ v142DynamicLibraryUnicode
- v141
+ v142
@@ -77,7 +77,7 @@
.so
- ..\..\..\lib\2.5\
+ ..\..\..\lib\2.7\
@@ -112,7 +112,7 @@
Disabled
- C:\msys64\local\ruby250vc\include\ruby-2.5.0;C:\msys64\local\ruby250vc\include\ruby-2.5.0\x64-mswin64_140;C:\msys64\local\include\libxml2;C:\msys64\mingw64\include;%(AdditionalIncludeDirectories)
+ C:\msys64\usr\local\ruby-2.7.2vc\include\ruby-2.7.0;C:\msys64\usr\local\ruby-2.7.2vc\include\ruby-2.7.0\x64-mswin64_140;C:\msys64\mingw64\include\libxml2;C:\msys64\mingw64\include;%(AdditionalIncludeDirectories)WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBXML_EXPORTS;%(PreprocessorDefinitions)EnableFastChecksMultiThreadedDebugDLL
@@ -126,9 +126,9 @@
- x64-vcruntime140-ruby250.lib;libxml2.lib;%(AdditionalDependencies)
+ x64-vcruntime140-ruby270.lib;libxml2.lib;%(AdditionalDependencies)$(OutDir)\$(TargetName)$(TargetExt)
- C:\msys64\local\ruby250vc\lib;C:\msys64\local\lib;%(AdditionalLibraryDirectories)
+ C:\msys64\usr\local\ruby-2.7.2vc\lib;C:\msys64\mingw64\lib;%(AdditionalLibraryDirectories)trueConsolefalse
diff --git a/lib/libxml-ruby.rb b/lib/libxml-ruby.rb
new file mode 100644
index 00000000..f9086c0a
--- /dev/null
+++ b/lib/libxml-ruby.rb
@@ -0,0 +1,30 @@
+# encoding: UTF-8
+
+# Load the C-based binding.
+begin
+ RUBY_VERSION =~ /(\d+.\d+)/
+ require "#{$1}/libxml_ruby"
+rescue LoadError
+ require "libxml_ruby"
+end
+
+# Load Ruby supporting code.
+require 'libxml/error'
+require 'libxml/parser'
+require 'libxml/document'
+require 'libxml/namespaces'
+require 'libxml/namespace'
+require 'libxml/node'
+require 'libxml/attributes'
+require 'libxml/attr'
+require 'libxml/attr_decl'
+require 'libxml/tree'
+require 'libxml/html_parser'
+require 'libxml/sax_parser'
+require 'libxml/sax_callbacks'
+
+#Schema Interface
+require 'libxml/schema'
+require 'libxml/schema/type'
+require 'libxml/schema/element'
+require 'libxml/schema/attribute'
diff --git a/lib/libxml.rb b/lib/libxml.rb
index 3cbd4b5a..e9390a87 100644
--- a/lib/libxml.rb
+++ b/lib/libxml.rb
@@ -1,30 +1,5 @@
# encoding: UTF-8
+#
+# This include is deprecated, use libxml-ruby instead!
-# Load the C-based binding.
-begin
- RUBY_VERSION =~ /(\d+.\d+)/
- require "#{$1}/libxml_ruby"
-rescue LoadError
- require "libxml_ruby"
-end
-
-# Load Ruby supporting code.
-require 'libxml/error'
-require 'libxml/parser'
-require 'libxml/document'
-require 'libxml/namespaces'
-require 'libxml/namespace'
-require 'libxml/node'
-require 'libxml/attributes'
-require 'libxml/attr'
-require 'libxml/attr_decl'
-require 'libxml/tree'
-require 'libxml/html_parser'
-require 'libxml/sax_parser'
-require 'libxml/sax_callbacks'
-
-#Schema Interface
-require 'libxml/schema'
-require 'libxml/schema/type'
-require 'libxml/schema/element'
-require 'libxml/schema/attribute'
+require 'libxml-ruby'
\ No newline at end of file
diff --git a/salsify_libxml_ruby.gemspec b/salsify_libxml_ruby.gemspec
index 0dbcaca2..18773147 100644
--- a/salsify_libxml_ruby.gemspec
+++ b/salsify_libxml_ruby.gemspec
@@ -34,8 +34,9 @@ Gem::Specification.new do |spec|
'lib/**/*.rb',
'script/**/*',
'test/**/*'])
+
spec.test_files = Dir.glob('test/test_*.rb')
- spec.required_ruby_version = '>= 1.8.6'
+ spec.required_ruby_version = '>= 2.5'
spec.add_development_dependency 'salsify_gem'
spec.add_development_dependency 'rake-compiler'
spec.add_development_dependency 'minitest'
diff --git a/test/test_attr.rb b/test/test_attr.rb
index 42f7c345..9df8b0b4 100644
--- a/test/test_attr.rb
+++ b/test/test_attr.rb
@@ -1,10 +1,10 @@
# encoding: UTF-8
-require File.expand_path('../test_helper', __FILE__)
+require_relative './test_helper'
class AttrNodeTest < Minitest::Test
def setup
- xp = XML::Parser.string(<<-EOS)
+ xp = LibXML::XML::Parser.string(<<-EOS)
@@ -42,7 +42,7 @@ def test_attr
# Get the attr_decl
attr = elem.attributes.get_attribute('access')
refute_nil(attr)
- assert_equal(XML::Node::ATTRIBUTE_NODE, attr.node_type)
+ assert_equal(LibXML::XML::Node::ATTRIBUTE_NODE, attr.node_type)
assert_equal('attribute', attr.node_type_name)
# Get its value
@@ -56,7 +56,7 @@ def test_attr_decl
# Get the attr_decl
attr_decl = elem.attributes.get_attribute('access')
refute_nil(attr_decl)
- assert_equal(XML::Node::ATTRIBUTE_DECL, attr_decl.node_type)
+ assert_equal(LibXML::XML::Node::ATTRIBUTE_DECL, attr_decl.node_type)
assert_equal('attribute declaration', attr_decl.node_type_name)
# Get its value
@@ -69,7 +69,7 @@ def test_type
attr_decl = elem.attributes.get_attribute('access')
refute_nil(attr_decl)
- assert_equal(XML::Node::ATTRIBUTE_DECL, attr_decl.node_type)
+ assert_equal(LibXML::XML::Node::ATTRIBUTE_DECL, attr_decl.node_type)
assert_equal('attribute declaration', attr_decl.node_type_name)
end
@@ -99,12 +99,12 @@ def test_prev
attr_decl = elem.attributes.get_attribute('access')
first_decl = attr_decl.prev
- assert_equal(XML::Node::ATTRIBUTE_DECL, first_decl.node_type)
+ assert_equal(LibXML::XML::Node::ATTRIBUTE_DECL, first_decl.node_type)
assert_equal('name', first_decl.name)
assert_nil(first_decl.value)
elem_decl = first_decl.prev
- assert_equal(XML::Node::ELEMENT_DECL, elem_decl.node_type)
+ assert_equal(LibXML::XML::Node::ELEMENT_DECL, elem_decl.node_type)
end
def test_next
@@ -127,6 +127,6 @@ def test_parent
attr_decl = elem.attributes.get_attribute('access')
parent = attr_decl.parent
- assert_instance_of(XML::Dtd, parent)
+ assert_instance_of(LibXML::XML::Dtd, parent)
end
end
\ No newline at end of file
diff --git a/test/test_attributes.rb b/test/test_attributes.rb
index cc09228e..ae1e5fa5 100644
--- a/test/test_attributes.rb
+++ b/test/test_attributes.rb
@@ -1,10 +1,10 @@
# encoding: UTF-8
-require File.expand_path('../test_helper', __FILE__)
+require_relative './test_helper'
class AttributesTest < Minitest::Test
def setup
- xp = XML::Parser.string(<<-EOS)
+ xp = LibXML::XML::Parser.string(<<-EOS)
mode))
end#test_canonicalize_with_w3c_c14n_3_1
@@ -30,12 +30,12 @@ def test_canonicalize_with_w3c_c14n_3_1
# (www.w3.org) 3.2 Whitespace in Document Content
# http://www.w3.org/TR/xml-c14n#Example-WhitespaceInContent
def test_canonicalize_with_w3c_c14n_3_2
- given_doc = XML::Document.file(self.path('c14n/given/example-2.xml'))
+ given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-2.xml'))
expected = IO.read(self.path('c14n/result/without-comments/example-2'))
assert_equal(expected, given_doc.canonicalize)
expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-2'))
- mode = XML::Document::XML_C14N_1_1
+ mode = LibXML::XML::Document::XML_C14N_1_1
assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
end
@@ -45,24 +45,24 @@ def test_canonicalize_with_w3c_c14n_3_2
# - Embedded DTD not parsed out of XML, therefore default attributes are
# not applied to canonicalization.
def test_canonicalize_with_w3c_c14n_3_3
- given_doc = XML::Document.file(self.path('c14n/given/example-3.xml'))
+ given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-3.xml'))
expected = IO.read(self.path('c14n/result/without-comments/example-3'))
assert_equal(expected, given_doc.canonicalize)
expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-3'))
- mode = XML::Document::XML_C14N_1_1
+ mode = LibXML::XML::Document::XML_C14N_1_1
assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
end
# (www.w3.org) 3.4 Character Modifications and Character References
# http://www.w3.org/TR/xml-c14n#Example-Chars
def test_canonicalize_with_w3c_c14n_3_4
- given_doc = XML::Document.file(self.path('c14n/given/example-4.xml'))
+ given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-4.xml'))
expected = IO.read(self.path('c14n/result/without-comments/example-4'))
assert_equal(expected, given_doc.canonicalize)
expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-4'))
- mode = XML::Document::XML_C14N_1_1
+ mode = LibXML::XML::Document::XML_C14N_1_1
assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
end
@@ -71,7 +71,7 @@ def test_canonicalize_with_w3c_c14n_3_4
# (2012-02-20) Failing likely due to a logic error
# - libxml2(c14n.c:1788) XML_ENTITY_REF_NODE is invalid node for parsing.
def test_canonicalize_with_w3c_c14n_3_5
- #given_doc = XML::Document.file(self.path('c14n/given/example-5.xml'))
+ #given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-5.xml'))
# With Comments
#expected_with_comments = IO.read(self.path('c14n/result/with-comments/example-5'))
@@ -84,7 +84,7 @@ def test_canonicalize_with_w3c_c14n_3_5
# TODO - CANNOT COMPLETE TEST unless libxml2 supports additional node types.
#assert_equal(expected_without_comments, given_doc.canonicalize(:comments => false))
#expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-5'))
- #mode = XML::Document::XML_C14N_1_1
+ #mode = LibXML::XML::Document::XML_C14N_1_1
# TODO - CANNOT COMPLETE TEST unless libxml2 supports additional node types.
#assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
@@ -93,20 +93,12 @@ def test_canonicalize_with_w3c_c14n_3_5
# (www.w3.org) 3.6 UTF-8 Encoding
# http://www.w3.org/TR/xml-c14n#Example-UTF8
def test_canonicalize_with_w3c_c14n_3_6
- given_doc = XML::Document.file(self.path('c14n/given/example-6.xml'))
- if defined?(Encoding)
- expected = IO.read(self.path('c14n/result/without-comments/example-6'), :encoding => Encoding::UTF_8)
- else
- expected = IO.read(self.path('c14n/result/without-comments/example-6'))
- end
+ given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-6.xml'))
+ expected = IO.read(self.path('c14n/result/without-comments/example-6'), :encoding => Encoding::UTF_8)
assert_equal(expected, given_doc.canonicalize)
- if defined?(Encoding)
- expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-6'), :encoding => Encoding::UTF_8)
- else
- expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-6'))
- end
- mode = XML::Document::XML_C14N_1_1
+ expected_1_1_without_comments = IO.read(self.path('c14n/result/1-1-without-comments/example-6'), :encoding => Encoding::UTF_8)
+ mode = LibXML::XML::Document::XML_C14N_1_1
assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
end
@@ -114,7 +106,7 @@ def test_canonicalize_with_w3c_c14n_3_6
# http://www.w3.org/TR/xml-c14n#Example-DocSubsets
def test_canonicalize_with_w3c_c14n_3_7
# Non Canonicalized Document
- # given_doc = XML::Document.file(self.path('c14n/given/example-7.xml'))
+ # given_doc = LibXML::XML::Document.file(self.path('c14n/given/example-7.xml'))
#expected = IO.read(self.path('c14n/result/without-comments/example-7'))
# e1_node = given_doc.find_first('ietf:e1', 'ietf:http://www.ietf.org')
diff --git a/test/test_deprecated_require.rb b/test/test_deprecated_require.rb
index fc1ab5ad..a5eabb45 100644
--- a/test/test_deprecated_require.rb
+++ b/test/test_deprecated_require.rb
@@ -4,9 +4,9 @@
class TestDeprecatedRequire < Minitest::Test
def test_basic
- xp = XML::Parser.string('onetwo')
- assert_instance_of(XML::Parser, xp)
+ xp = LibXML::XML::Parser.string('onetwo')
+ assert_instance_of(LibXML::XML::Parser, xp)
@doc = xp.parse
- assert_instance_of(XML::Document, @doc)
+ assert_instance_of(LibXML::XML::Document, @doc)
end
end
diff --git a/test/test_document.rb b/test/test_document.rb
index d0e1e65d..2e1654dc 100644
--- a/test/test_document.rb
+++ b/test/test_document.rb
@@ -1,12 +1,12 @@
# encoding: UTF-8
-require File.expand_path('../test_helper', __FILE__)
+require_relative './test_helper'
class TestDocument < Minitest::Test
def setup
- xp = XML::Parser.string('onetwo')
- assert_instance_of(XML::Parser, xp)
+ xp = LibXML::XML::Parser.string('onetwo')
+ assert_instance_of(LibXML::XML::Parser, xp)
@doc = xp.parse
- assert_instance_of(XML::Document, @doc)
+ assert_instance_of(LibXML::XML::Document, @doc)
end
def teardown
@@ -14,24 +14,24 @@ def teardown
end
def test_klass
- assert_instance_of(XML::Document, @doc)
+ assert_instance_of(LibXML::XML::Document, @doc)
end
def test_context
context = @doc.context
- assert_instance_of(XML::XPath::Context, context)
+ assert_instance_of(LibXML::XML::XPath::Context, context)
end
def test_find
set = @doc.find('/ruby_array/fixnum')
- assert_instance_of(XML::XPath::Object, set)
+ assert_instance_of(LibXML::XML::XPath::Object, set)
assert_raises(NoMethodError) {
set.xpath
}
end
def test_compression
- if XML.enabled_zlib?
+ if LibXML::XML.enabled_zlib?
0.upto(9) do |i|
assert_equal(i, @doc.compression = i)
assert_equal(i, @doc.compression)
@@ -59,30 +59,30 @@ def test_compression
def test_version
assert_equal('1.0', @doc.version)
- doc = XML::Document.new('6.9')
+ doc = LibXML::XML::Document.new('6.9')
assert_equal('6.9', doc.version)
end
def test_write_root
- @doc.root = XML::Node.new('rubynet')
- assert_instance_of(XML::Node, @doc.root)
- assert_instance_of(XML::Document, @doc.root.doc)
+ @doc.root = LibXML::XML::Node.new('rubynet')
+ assert_instance_of(LibXML::XML::Node, @doc.root)
+ assert_instance_of(LibXML::XML::Document, @doc.root.doc)
assert_equal("\n\n",
@doc.to_s(:indent => false))
end
def test_doc_node_type
- assert_equal(XML::Node::DOCUMENT_NODE, XML::Document.new.node_type)
+ assert_equal(LibXML::XML::Node::DOCUMENT_NODE, LibXML::XML::Document.new.node_type)
end
def test_doc_node_type_name
- assert_equal('document_xml', XML::Document.new.node_type_name)
+ assert_equal('document_xml', LibXML::XML::Document.new.node_type_name)
end
def test_xhtml
- doc = XML::Document.new
+ doc = LibXML::XML::Document.new
assert(!doc.xhtml?)
- XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true
+ LibXML::XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true
assert(doc.xhtml?)
end
@@ -90,10 +90,10 @@ def test_document_root
doc1 = LibXML::XML::Document.string("")
doc2 = LibXML::XML::Document.string("")
- error = assert_raises(XML::Error) do
+ error = assert_raises(LibXML::XML::Error) do
doc1.root = doc2.root
end
- assert_equal(" Nodes belong to different documents. You must first import the node by calling XML::Document.import.",
+ assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.",
error.to_s)
doc2.root << doc2.import(doc1.root)
@@ -105,16 +105,16 @@ def test_document_root
end
def test_import_node
- doc1 = XML::Parser.string('').parse
- doc2 = XML::Parser.string('').parse
+ doc1 = LibXML::XML::Parser.string('').parse
+ doc2 = LibXML::XML::Parser.string('').parse
node = doc1.root.child
- error = assert_raises(XML::Error) do
+ error = assert_raises(LibXML::XML::Error) do
doc2.root << node
end
- assert_equal(" Nodes belong to different documents. You must first import the node by calling XML::Document.import.",
+ assert_equal(" Nodes belong to different documents. You must first import the node by calling LibXML::XML::Document.import.",
error.to_s)
doc2.root << doc2.import(node)
@@ -122,4 +122,10 @@ def test_import_node
assert_equal("",
doc2.root.to_s(:indent => false))
end
+
+ def test_nonet
+ xml_string = 'onetwo'
+ xml = LibXML::XML::Document.string(xml_string, options: LibXML::XML::Parser::Options::NONET)
+ schema_document = LibXML::XML::Document.file('d:/src/libxml-ruby/test/model/atom.xml', options: LibXML::XML::Parser::Options::NONET)
+ end
end
diff --git a/test/test_document_write.rb b/test/test_document_write.rb
index 462b2579..f8970ef5 100644
--- a/test/test_document_write.rb
+++ b/test/test_document_write.rb
@@ -1,6 +1,6 @@
# encoding: UTF-8
-require File.expand_path('../test_helper', __FILE__)
+require_relative './test_helper'
require 'tmpdir'
class TestDocumentWrite < Minitest::Test
@@ -8,56 +8,41 @@ def setup
@file_name = "model/bands.utf-8.xml"
# Strip spaces to make testing easier
- XML.default_keep_blanks = false
+ LibXML::XML.default_keep_blanks = false
file = File.join(File.dirname(__FILE__), @file_name)
- @doc = XML::Document.file(file)
+ @doc = LibXML::XML::Document.file(file)
end
def teardown
- XML.default_keep_blanks = true
+ LibXML::XML.default_keep_blanks = true
@doc = nil
end
# --- to_s tests ---
def test_to_s_default
# Default to_s has indentation
- if defined?(Encoding)
- assert_equal("\n\n M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n",
- @doc.to_s)
- else
- assert_equal("\n\n M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n",
- @doc.to_s)
- end
+ assert_equal("\n\n M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n",
+ @doc.to_s)
end
def test_to_s_no_global_indentation
# No indentation due to global setting
- XML.indent_tree_output = false
+ LibXML::XML.indent_tree_output = false
value = @doc.to_s
- if defined?(Encoding)
- assert_equal(Encoding::UTF_8, value.encoding)
- assert_equal("\n\nM\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\nIron Maiden is a British heavy metal band formed in 1975.\n\n",
- value)
- else
- assert_equal("\n\nM\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.\nIron Maiden is a British heavy metal band formed in 1975.\n\n",
- value)
- end
+ assert_equal(Encoding::UTF_8, value.encoding)
+ assert_equal("\n\nM\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\nIron Maiden is a British heavy metal band formed in 1975.\n\n",
+ value)
ensure
- XML.indent_tree_output = true
+ LibXML::XML.indent_tree_output = true
end
def test_to_s_no_indentation
# No indentation due to local setting
value = @doc.to_s(:indent => false)
- if defined?(Encoding)
- assert_equal(Encoding::UTF_8, value.encoding)
- assert_equal("\nM\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n",
- value)
- else
- assert_equal("\nM\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n",
- value)
- end
+ assert_equal(Encoding::UTF_8, value.encoding)
+ assert_equal("\nM\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n",
+ value)
end
def test_to_s_encoding
@@ -66,28 +51,18 @@ def test_to_s_encoding
# UTF8:
# ö - c3 b6 in hex, \303\266 in octal
# ü - c3 bc in hex, \303\274 in octal
- value = @doc.to_s(:encoding => XML::Encoding::UTF_8)
- if defined?(Encoding)
- assert_equal(Encoding::UTF_8, value.encoding)
- assert_equal("\n\n M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n",
- value)
- else
- assert_equal("\n\n M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n",
- value)
- end
+ value = @doc.to_s(:encoding => LibXML::XML::Encoding::UTF_8)
+ assert_equal(Encoding::UTF_8, value.encoding)
+ assert_equal("\n\n M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n",
+ value)
# ISO_8859_1:
# ö - f6 in hex, \366 in octal
# ü - fc in hex, \374 in octal
- value = @doc.to_s(:encoding => XML::Encoding::ISO_8859_1)
- if defined?(Encoding)
- assert_equal(Encoding::ISO8859_1, value.encoding)
- assert_equal("\n\n M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n".force_encoding(Encoding::ISO8859_1),
- @doc.to_s(:encoding => XML::Encoding::ISO_8859_1))
- else
- assert_equal("\n\n M\366tley Cr\374e is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n",
- @doc.to_s(:encoding => XML::Encoding::ISO_8859_1))
- end
+ value = @doc.to_s(:encoding => LibXML::XML::Encoding::ISO_8859_1)
+ assert_equal(Encoding::ISO8859_1, value.encoding)
+ assert_equal("\n\n M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n".force_encoding(Encoding::ISO8859_1),
+ @doc.to_s(:encoding => LibXML::XML::Encoding::ISO_8859_1))
# Invalid encoding
error = assert_raises(ArgumentError) do
@@ -103,16 +78,10 @@ def test_save_utf8
bytes = @doc.save(temp_filename)
assert_equal(305, bytes)
- if defined?(Encoding)
- contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8)
- assert_equal(Encoding::UTF_8, contents.encoding)
- assert_equal("\n\n M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n",
- contents)
- else
- contents = File.read(temp_filename)
- assert_equal("\n\n M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n",
- contents)
- end
+ contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8)
+ assert_equal(Encoding::UTF_8, contents.encoding)
+ assert_equal("\n\n M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n",
+ contents)
ensure
File.delete(temp_filename)
end
@@ -123,53 +92,35 @@ def test_save_utf8_no_indents
bytes = @doc.save(temp_filename, :indent => false)
assert_equal(298, bytes)
- if defined?(Encoding)
- contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8)
- assert_equal("\nM\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n",
- contents)
- else
- contents = File.read(temp_filename)
- assert_equal("\nM\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n",
- contents)
- end
+ contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8)
+ assert_equal("\nM\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n",
+ contents)
ensure
File.delete(temp_filename)
end
def test_save_iso_8859_1
temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1.xml")
- bytes = @doc.save(temp_filename, :encoding => XML::Encoding::ISO_8859_1)
+ bytes = @doc.save(temp_filename, :encoding => LibXML::XML::Encoding::ISO_8859_1)
assert_equal(304, bytes)
- if defined?(Encoding)
- contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1)
- assert_equal(Encoding::ISO8859_1, contents.encoding)
- assert_equal("\n\n M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n".force_encoding(Encoding::ISO8859_1),
- contents)
- else
- contents = File.read(temp_filename)
- assert_equal("\n\n M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n",
- contents)
- end
+ contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1)
+ assert_equal(Encoding::ISO8859_1, contents.encoding)
+ assert_equal("\n\n M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.\n Iron Maiden is a British heavy metal band formed in 1975.\n\n".force_encoding(Encoding::ISO8859_1),
+ contents)
ensure
File.delete(temp_filename)
end
def test_save_iso_8859_1_no_indent
temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1_no_indent.xml")
- bytes = @doc.save(temp_filename, :indent => false, :encoding => XML::Encoding::ISO_8859_1)
+ bytes = @doc.save(temp_filename, :indent => false, :encoding => LibXML::XML::Encoding::ISO_8859_1)
assert_equal(297, bytes)
- if defined?(Encoding)
- contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1)
- assert_equal(Encoding::ISO8859_1, contents.encoding)
- assert_equal("\nM\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n".force_encoding(Encoding::ISO8859_1),
- contents)
- else
- contents = File.read(temp_filename)
- assert_equal("\nM\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n",
- contents)
- end
+ contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1)
+ assert_equal(Encoding::ISO8859_1, contents.encoding)
+ assert_equal("\nM\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.\n".force_encoding(Encoding::ISO8859_1),
+ contents)
ensure
File.delete(temp_filename)
end
diff --git a/test/test_dtd.rb b/test/test_dtd.rb
index f2dea424..9f154bbb 100644
--- a/test/test_dtd.rb
+++ b/test/test_dtd.rb
@@ -1,11 +1,11 @@
# encoding: UTF-8
-require File.expand_path('../test_helper', __FILE__)
+require_relative './test_helper'
class TestDtd < Minitest::Test
def setup
- xp = XML::Parser.string(<<-EOS)
+ xp = LibXML::XML::Parser.string(<<-EOS)
Colorado
Lots of nice mountains
@@ -19,7 +19,7 @@ def teardown
end
def dtd
- XML::Dtd.new(<<-EOS)
+ LibXML::XML::Dtd.new(<<-EOS)
XML::Parser::Options::DTDLOAD).parse
+ LibXML::XML::Parser.string(xml, :options => LibXML::XML::Parser::Options::DTDLOAD).parse
assert_equal(1, errors.length)
assert_equal("Warning: failed to load external entity \"test.dtd\" at :1.",
errors[0].to_s)
ensure
- XML.default_load_external_dtd = false
- XML::Error.reset_handler
+ LibXML::XML.default_load_external_dtd = false
+ LibXML::XML::Error.reset_handler
end
end
diff --git a/test/test_encoding.rb b/test/test_encoding.rb
index 97d84279..00417018 100644
--- a/test/test_encoding.rb
+++ b/test/test_encoding.rb
@@ -1,6 +1,6 @@
# encoding: UTF-8
-require File.expand_path('../test_helper', __FILE__)
+require_relative './test_helper'
# Code UTF8 Latin1 Hex
# m 109 109 6D
@@ -39,24 +39,24 @@ def load_encoding(encoding)
file = file_for_encoding(encoding)
# Strip spaces to make testing easier
- XML.default_keep_blanks = false
- @doc = XML::Document.file(file)
- XML.default_keep_blanks = true
+ LibXML::XML.default_keep_blanks = false
+ @doc = LibXML::XML::Document.file(file)
+ LibXML::XML.default_keep_blanks = true
end
def test_encoding
- doc = XML::Document.new
- assert_equal(XML::Encoding::NONE, doc.encoding)
- assert_equal(Encoding::ASCII_8BIT, doc.rb_encoding) if defined?(Encoding)
+ doc = LibXML::XML::Document.new
+ assert_equal(LibXML::XML::Encoding::NONE, doc.encoding)
+ assert_equal(Encoding::ASCII_8BIT, doc.rb_encoding)
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
- doc = XML::Document.file(file)
- assert_equal(XML::Encoding::UTF_8, doc.encoding)
- assert_equal(Encoding::UTF_8, doc.rb_encoding) if defined?(Encoding)
+ doc = LibXML::XML::Document.file(file)
+ assert_equal(LibXML::XML::Encoding::UTF_8, doc.encoding)
+ assert_equal(Encoding::UTF_8, doc.rb_encoding)
- doc.encoding = XML::Encoding::ISO_8859_1
- assert_equal(XML::Encoding::ISO_8859_1, doc.encoding)
- assert_equal(Encoding::ISO8859_1, doc.rb_encoding) if defined?(Encoding)
+ doc.encoding = LibXML::XML::Encoding::ISO_8859_1
+ assert_equal(LibXML::XML::Encoding::ISO_8859_1, doc.encoding)
+ assert_equal(Encoding::ISO8859_1, doc.rb_encoding)
end
def test_no_internal_encoding_iso_8859_1
@@ -123,7 +123,7 @@ def test_internal_encoding_utf_8
end
def test_encoding_conversions
- assert_equal("UTF-8", XML::Encoding.to_s(XML::Encoding::UTF_8))
- assert_equal(XML::Encoding::UTF_8, XML::Encoding.from_s("UTF-8"))
+ assert_equal("UTF-8", LibXML::XML::Encoding.to_s(LibXML::XML::Encoding::UTF_8))
+ assert_equal(LibXML::XML::Encoding::UTF_8, LibXML::XML::Encoding.from_s("UTF-8"))
end
end
diff --git a/test/test_encoding_sax.rb b/test/test_encoding_sax.rb
index 67ef0044..f1b81c6d 100644
--- a/test/test_encoding_sax.rb
+++ b/test/test_encoding_sax.rb
@@ -1,5 +1,5 @@
# encoding: UTF-8
-require File.expand_path('../test_helper', __FILE__)
+require_relative './test_helper'
class SaxEncodingCallbacks
attr_reader :encoding
@@ -102,13 +102,13 @@ def file_for_encoding(encoding)
end
def test_encoding_iso_8859_1
- parser = XML::SaxParser.file(file_for_encoding(Encoding::ISO_8859_1))
+ parser = LibXML::XML::SaxParser.file(file_for_encoding(Encoding::ISO_8859_1))
parser.callbacks = SaxEncodingCallbacks.new
parser.parse
end
def test_encoding_utf8
- parser = XML::SaxParser.file(file_for_encoding(Encoding::UTF_8))
+ parser = LibXML::XML::SaxParser.file(file_for_encoding(Encoding::UTF_8))
parser.callbacks = SaxEncodingCallbacks.new
parser.parse
end
diff --git a/test/test_error.rb b/test/test_error.rb
index ca25ca40..ab689b6a 100644
--- a/test/test_error.rb
+++ b/test/test_error.rb
@@ -1,42 +1,42 @@
# encoding: UTF-8
-require File.expand_path('../test_helper', __FILE__)
+require_relative './test_helper'
require 'stringio'
class TestError < Minitest::Test
# def test_error_codes
- # assert_equal(4, XML::Error::DTD)
- # assert_equal(4, XML::Error.const_get('DTD'))
+ # assert_equal(4, LibXML::XML::Error::DTD)
+ # assert_equal(4, LibXML::XML::Error.const_get('DTD'))
#
- # assert_equal(4, XML::Error::DOCUMENT_EMPTY)
- # assert_equal(4, XML::Error.const_get('DOCUMENT_EMPTY'))
+ # assert_equal(4, LibXML::XML::Error::DOCUMENT_EMPTY)
+ # assert_equal(4, LibXML::XML::Error.const_get('DOCUMENT_EMPTY'))
# end
#
# def test_invalid_handler
# assert_raises(RuntimeError) do
- # XML::Error.set_handler
+ # LibXML::XML::Error.set_handler
# end
# end
#
# def test_handler
# exception = nil
- # XML::Error.set_handler do |error|
+ # LibXML::XML::Error.set_handler do |error|
# exception = error
# end
#
# # Raise the error
- # error = assert_raises(XML::Error) do
- # XML::Reader.string('').parse
+ # assert_raises(LibXML::XML::Error) do
+ # LibXML::XML::Parser.string('').parse
# end
# ensure
# Object.const_set(:STDERR, original_stderr)
@@ -87,14 +87,14 @@ class TestError < Minitest::Test
# end
#
# def test_no_hanlder
- # XML::Error.reset_handler
+ # LibXML::XML::Error.reset_handler
# output = StringIO.new
# original_stderr = Object::STDERR
#
# Object.const_set(:STDERR, output)
# begin
- # assert_raises(XML::Error) do
- # XML::Parser.string('').parse
+ # assert_raises(LibXML::XML::Error) do
+ # LibXML::XML::Parser.string('').parse
# end
# ensure
# Object.const_set(:STDERR, original_stderr)
@@ -103,41 +103,41 @@ class TestError < Minitest::Test
# end
#
# def test_parse_error
- # exception = assert_raises(XML::Error) do
- # XML::Parser.string('').parse
+ # exception = assert_raises(LibXML::XML::Error) do
+ # LibXML::XML::Parser.string('').parse
# end
#
- # assert_instance_of(XML::Error, exception)
+ # assert_instance_of(LibXML::XML::Error, exception)
# assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.", exception.message)
- # assert_equal(XML::Error::PARSER, exception.domain)
- # assert_equal(XML::Error::TAG_NAME_MISMATCH, exception.code)
- # assert_equal(XML::Error::FATAL, exception.level)
+ # assert_equal(LibXML::XML::Error::PARSER, exception.domain)
+ # assert_equal(LibXML::XML::Error::TAG_NAME_MISMATCH, exception.code)
+ # assert_equal(LibXML::XML::Error::FATAL, exception.level)
# assert_nil(exception.file)
# assert_equal(1, exception.line)
# end
#
# def test_xpath_error
- # doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml'))
+ # doc = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml'))
#
- # exception = assert_raises(XML::Error) do
+ # exception = assert_raises(LibXML::XML::Error) do
# doc.find('/foo[bar=test')
# end
#
- # assert_instance_of(XML::Error, exception)
+ # assert_instance_of(LibXML::XML::Error, exception)
# assert_equal("Error: Invalid predicate.", exception.message)
- # assert_equal(XML::Error::XPATH, exception.domain)
- # assert_equal(XML::Error::XPATH_INVALID_PREDICATE_ERROR, exception.code)
- # assert_equal(XML::Error::ERROR, exception.level)
+ # assert_equal(LibXML::XML::Error::XPATH, exception.domain)
+ # assert_equal(LibXML::XML::Error::XPATH_INVALID_PREDICATE_ERROR, exception.code)
+ # assert_equal(LibXML::XML::Error::ERROR, exception.level)
# assert_nil(exception.file)
# assert_nil(nil)
# end
def test_double_parse
- XML::Parser.register_error_handler(lambda {|msg| nil })
- parser = XML::Parser.string("something")
+ LibXML::XML::Parser.register_error_handler(lambda {|msg| nil })
+ parser = LibXML::XML::Parser.string("something")
parser.parse
- error = assert_raises(XML::Error) do
+ error = assert_raises(LibXML::XML::Error) do
# Try parsing a second time
parser.parse
end
@@ -146,7 +146,7 @@ def test_double_parse
end
# def test_libxml_parser_empty_string
- # xp = XML::Parser.new
+ # xp = LibXML::XML::Parser.new
#
# error = assert_raises(TypeError) do
# xp.string = nil
@@ -160,19 +160,19 @@ def test_double_parse
# end
#
# def test_error_domain_to_s
- # exception = assert_raises(XML::Error) do
- # XML::Parser.string('').parse
+ # exception = assert_raises(LibXML::XML::Error) do
+ # LibXML::XML::Parser.string('').parse
# end
#
- # assert_equal(XML::Error::PARSER, exception.domain)
+ # assert_equal(LibXML::XML::Error::PARSER, exception.domain)
# assert_equal("PARSER",exception.domain_to_s)
# end
#
# def test_error_code_to_s
- # exception = assert_raises(XML::Error) do
- # XML::Parser.string('').parse
+ # exception = assert_raises(LibXML::XML::Error) do
+ # LibXML::XML::Parser.string('').parse
# end
- # assert_equal(XML::Error::ENTITYREF_SEMICOL_MISSING, exception.code)
+ # assert_equal(LibXML::XML::Error::ENTITYREF_SEMICOL_MISSING, exception.code)
# assert_equal("ENTITYREF_SEMICOL_MISSING",exception.code_to_s)
# end
end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index a152ad90..b1b72cce 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -2,13 +2,6 @@
# To make testing/debugging easier, test within this source tree versus an installed gem
-dir = File.dirname(__FILE__)
-root = File.expand_path(File.join(dir, '..'))
-lib = File.expand_path(File.join(root, 'lib'))
-ext = File.expand_path(File.join(root, 'ext', 'libxml'))
-
-$LOAD_PATH << lib
-$LOAD_PATH << ext
-
-require 'xml'
+require 'bundler/setup'
require 'minitest/autorun'
+require 'libxml-ruby'
diff --git a/test/test_html_parser.rb b/test/test_html_parser.rb
index c8e39413..aa3cda2a 100644
--- a/test/test_html_parser.rb
+++ b/test/test_html_parser.rb
@@ -1,6 +1,6 @@
# encoding: UTF-8
-require File.expand_path('../test_helper', __FILE__)
+require_relative './test_helper'
require 'stringio'
class HTMLParserTest < Minitest::Test
@@ -10,15 +10,15 @@ def html_file
# ----- Sources ------
def test_file
- xp = XML::HTMLParser.file(html_file)
- assert_instance_of(XML::HTMLParser, xp)
+ xp = LibXML::XML::HTMLParser.file(html_file)
+ assert_instance_of(LibXML::XML::HTMLParser, xp)
doc = xp.parse
refute_nil(doc)
end
def test_noexistent_file
- error = assert_raises(XML::Error) do
- XML::HTMLParser.file('i_dont_exist.xml')
+ error = assert_raises(LibXML::XML::Error) do
+ LibXML::XML::HTMLParser.file('i_dont_exist.xml')
end
assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
@@ -26,7 +26,7 @@ def test_noexistent_file
def test_nil_file
error = assert_raises(TypeError) do
- XML::HTMLParser.file(nil)
+ LibXML::XML::HTMLParser.file(nil)
end
assert_match(/nil into String/, error.to_s)
@@ -34,11 +34,11 @@ def test_nil_file
def test_io
File.open(html_file) do |io|
- xp = XML::HTMLParser.io(io)
- assert_instance_of(XML::HTMLParser, xp)
+ xp = LibXML::XML::HTMLParser.io(io)
+ assert_instance_of(LibXML::XML::HTMLParser, xp)
doc = xp.parse
- assert_instance_of(XML::Document, doc)
+ assert_instance_of(LibXML::XML::Document, doc)
end
end
@@ -46,7 +46,7 @@ def test_io_gc
# Test that the reader keeps a reference
# to the io object
file = File.open(html_file)
- parser = XML::HTMLParser.io(file)
+ parser = LibXML::XML::HTMLParser.io(file)
file = nil
GC.start
assert(parser.parse)
@@ -54,7 +54,7 @@ def test_io_gc
def test_nil_io
error = assert_raises(TypeError) do
- XML::HTMLParser.io(nil)
+ LibXML::XML::HTMLParser.io(nil)
end
assert_equal("Must pass in an IO object", error.to_s)
@@ -63,27 +63,27 @@ def test_nil_io
def test_string_io
data = File.read(html_file)
io = StringIO.new(data)
- xp = XML::HTMLParser.io(io)
- assert_instance_of(XML::HTMLParser, xp)
+ xp = LibXML::XML::HTMLParser.io(io)
+ assert_instance_of(LibXML::XML::HTMLParser, xp)
doc = xp.parse
- assert_instance_of(XML::Document, doc)
+ assert_instance_of(LibXML::XML::Document, doc)
end
def test_string
str = '
hi
'
- xp = XML::HTMLParser.string(str)
+ xp = LibXML::XML::HTMLParser.string(str)
- assert_instance_of(XML::HTMLParser, xp)
- assert_instance_of(XML::HTMLParser, xp)
+ assert_instance_of(LibXML::XML::HTMLParser, xp)
+ assert_instance_of(LibXML::XML::HTMLParser, xp)
doc = xp.parse
- assert_instance_of(XML::Document, doc)
+ assert_instance_of(LibXML::XML::Document, doc)
end
def test_nil_string
error = assert_raises(TypeError) do
- XML::HTMLParser.string(nil)
+ LibXML::XML::HTMLParser.string(nil)
end
assert_equal("wrong argument type nil (expected String)", error.to_s)
@@ -98,26 +98,26 @@ def test_parse
Hello World
EOS
- parser = XML::HTMLParser.string(html, :options => XML::HTMLParser::Options::NOBLANKS)
+ parser = LibXML::XML::HTMLParser.string(html, :options => LibXML::XML::HTMLParser::Options::NOBLANKS)
doc = parser.parse
- assert_instance_of XML::Document, doc
+ assert_instance_of LibXML::XML::Document, doc
root = doc.root
- assert_instance_of XML::Node, root
+ assert_instance_of LibXML::XML::Node, root
assert_equal 'html', root.name
head = root.child
- assert_instance_of XML::Node, head
+ assert_instance_of LibXML::XML::Node, head
assert_equal 'head', head.name
meta = head.child
- assert_instance_of XML::Node, meta
+ assert_instance_of LibXML::XML::Node, meta
assert_equal 'meta', meta.name
assert_equal 'keywords', meta[:name]
assert_equal 'nasty', meta[:content]
body = head.next
- assert_instance_of XML::Node, body
+ assert_instance_of LibXML::XML::Node, body
assert_equal 'body', body.name
hello = body.child
@@ -125,21 +125,21 @@ def test_parse
# cant figure our why or how, so this skips it if there
hello = hello.child if hello.name == "p"
- assert_instance_of XML::Node, hello
+ assert_instance_of LibXML::XML::Node, hello
assert_equal 'Hello', hello.content
br = hello.next
- assert_instance_of XML::Node, br
+ assert_instance_of LibXML::XML::Node, br
assert_equal 'br', br.name
world = br.next
- assert_instance_of XML::Node, world
+ assert_instance_of LibXML::XML::Node, world
assert_equal 'World', world.content
end
def test_no_implied
html = "hello world"
- parser = XML::HTMLParser.string(html, :options => XML::HTMLParser::Options::NOIMPLIED)
+ parser = LibXML::XML::HTMLParser.string(html, :options => LibXML::XML::HTMLParser::Options::NOIMPLIED)
doc = parser.parse
assert_equal("