xmlhash 1.3.3 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 1.3.4 / 2012-12-04
2
+
3
+ * "upgrade" latin1 and us-ascii to utf-8 automatically
4
+
1
5
  === 1.3.3 / 2012-11-06
2
6
  * <files/> should return [] not [{}]
3
7
 
@@ -199,6 +199,8 @@ static VALUE parse_xml_hash(VALUE self, VALUE rb_xml)
199
199
  Check_Type(rb_xml, T_STRING);
200
200
  #ifdef HAVE_RUBY_ENCODING_H
201
201
  m_current_encoding = rb_enc_get(rb_xml);
202
+ if (m_current_encoding == rb_ascii8bit_encoding() || m_current_encoding == rb_usascii_encoding())
203
+ m_current_encoding = rb_utf8_encoding();
202
204
  #endif
203
205
 
204
206
  data = (char*)calloc(RSTRING_LEN(rb_xml), sizeof(char));
data/lib/xmlhash.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'xmlhash/xmlhash'
2
2
 
3
3
  module Xmlhash
4
- VERSION = '1.3.3'
4
+ VERSION = '1.3.4'
5
5
 
6
6
  class XMLHash < Hash
7
7
 
data/test/test_xmlhash.rb CHANGED
@@ -124,4 +124,35 @@ eos
124
124
  ret = Xmlhash.parse(xml)
125
125
  assert_equal ret.elements('files'), []
126
126
  end
127
+
128
+ def test_utf8
129
+ xml = '<package name="libconfig" project="home:coolo">
130
+ <title>libconfig &#8211; C/C++ Configuration File Library</title>
131
+ <description>Libconfig is a simple library for processing structured configuration files, like this one: test.cfg. This file format is more compact and more readable than XML. And unlike XML, it is type-aware, so it is not necessary to do string parsing in application code.
132
+
133
+ Libconfig is very compact &#8212; just 38K for the stripped C shared library (less than one-fourth the size of the expat XML parser library) and 66K for the stripped C++ shared library. This makes it well-suited for memory-constrained systems like handheld devices.
134
+
135
+ The library includes bindings for both the C and C++ languages. It works on POSIX-compliant UNIX systems (GNU/Linux, Mac OS X, Solaris, FreeBSD) and Windows (2000, XP and later).</description>
136
+ </package>'
137
+ xh = Xmlhash.parse(xml)
138
+ assert_equal "UTF-8", xh['title'].encoding.to_s
139
+
140
+ # now try with different input encoding
141
+ xml.encode!('US-ASCII')
142
+ xh = Xmlhash.parse(xml)
143
+ assert_equal "UTF-8", xh['title'].encoding.to_s
144
+
145
+ xml = '<?xml version="1.0" encoding="ISO-8859-1"?>
146
+ <package><title>Äöß</title></package>'
147
+ xml.encode!('ISO-8859-1')
148
+ xh = Xmlhash.parse(xml)
149
+ assert_equal "ISO-8859-1", xh['title'].encoding.to_s
150
+
151
+ xml = '<?xml version="1.0" encoding="ISO-8859-1"?>
152
+ <package><title>&#228;&#211;&#254;</title></package>'
153
+ xml.encode!('US-ASCII')
154
+ xh = Xmlhash.parse(xml)
155
+ assert_equal "UTF-8", xh['title'].encoding.to_s
156
+
157
+ end
127
158
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xmlhash
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.3.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-06 00:00:00.000000000 Z
12
+ date: 2012-12-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pkg-config
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: '3.1'
69
+ version: '3.3'
70
70
  type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,7 +74,7 @@ dependencies:
74
74
  requirements:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: '3.1'
77
+ version: '3.3'
78
78
  description: ! 'A small C module that wraps libxml2''s xmlreader to parse a XML
79
79
 
80
80
  string into a ruby hash'