xmlhash 1.3.7 → 1.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/Gemfile +1 -0
- data/History.txt +4 -0
- data/README.txt +1 -1
- data/ext/xmlhash/extconf.rb +1 -0
- data/ext/xmlhash/xmlhash.c +7 -1
- data/lib/xmlhash.rb +2 -3
- data/test/test_xmlhash.rb +77 -73
- metadata +24 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3f72be19a08e60ff2efe59afb44753d23f3bb9eea969e98c6dbb80e03df376a8
|
4
|
+
data.tar.gz: e1114dead31f0e4ecedf639a22dac1f114ba136f21875183b35a65dd88867e5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c57699c0ca0943c498b154dfefd9d9e2039fd05daf19427852417b634dd364b75c0f03280e0017ea1da04745684e82e19d68176ef3382c864db111c9dfb292c2
|
7
|
+
data.tar.gz: fb8689064ee31b7dcd827682ac0d25bbc1b7c8eed41284118d283ec6aecd59a076e984d37c9539b3dbbd70fdd8b75f940743004cc86fe1846c9e86fa5fcd2606
|
data/Gemfile
CHANGED
data/History.txt
CHANGED
data/README.txt
CHANGED
@@ -37,7 +37,7 @@ and generate the RDoc.
|
|
37
37
|
|
38
38
|
(The MIT License)
|
39
39
|
|
40
|
-
Copyright (c) 2012 Stephan Kulow
|
40
|
+
Copyright (c) 2012-2022 Stephan Kulow
|
41
41
|
|
42
42
|
Permission is hereby granted, free of charge, to any person obtaining
|
43
43
|
a copy of this software and associated documentation files (the
|
data/ext/xmlhash/extconf.rb
CHANGED
data/ext/xmlhash/xmlhash.c
CHANGED
@@ -19,6 +19,7 @@
|
|
19
19
|
static VALUE m_current = Qnil;
|
20
20
|
static VALUE m_stack = Qnil;
|
21
21
|
static VALUE m_cstring = Qnil;
|
22
|
+
static VALUE m_mutex = Qnil;
|
22
23
|
static VALUE m_result = Qnil;
|
23
24
|
static VALUE m_xmlClass = Qnil;
|
24
25
|
#ifdef HAVE_RUBY_ENCODING_H
|
@@ -195,6 +196,8 @@ void processNode(xmlTextReaderPtr reader)
|
|
195
196
|
|
196
197
|
static VALUE parse_xml_hash(VALUE self, VALUE rb_xml)
|
197
198
|
{
|
199
|
+
rb_mutex_lock(m_mutex);
|
200
|
+
|
198
201
|
char *data;
|
199
202
|
xmlTextReaderPtr reader;
|
200
203
|
int ret;
|
@@ -212,7 +215,7 @@ static VALUE parse_xml_hash(VALUE self, VALUE rb_xml)
|
|
212
215
|
memcpy(data, StringValuePtr(rb_xml), RSTRING_LEN(rb_xml));
|
213
216
|
|
214
217
|
reader = xmlReaderForMemory(data, RSTRING_LEN(rb_xml),
|
215
|
-
NULL, NULL,
|
218
|
+
NULL, NULL, XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_HUGE );
|
216
219
|
init_XmlhashParserData();
|
217
220
|
|
218
221
|
if (reader != NULL) {
|
@@ -231,6 +234,7 @@ static VALUE parse_xml_hash(VALUE self, VALUE rb_xml)
|
|
231
234
|
#ifdef HAVE_RUBY_ENCODING_H
|
232
235
|
m_current_encoding = 0;
|
233
236
|
#endif
|
237
|
+
rb_mutex_unlock(m_mutex);
|
234
238
|
return m_result;
|
235
239
|
}
|
236
240
|
|
@@ -239,6 +243,8 @@ void Init_xmlhash()
|
|
239
243
|
VALUE mXmlhash;
|
240
244
|
|
241
245
|
LIBXML_TEST_VERSION
|
246
|
+
m_mutex = rb_mutex_new();
|
247
|
+
rb_global_variable(&m_mutex);
|
242
248
|
mXmlhash = rb_define_module("Xmlhash");
|
243
249
|
m_xmlClass = rb_define_class_under(mXmlhash, "XMLHash", rb_cHash);
|
244
250
|
rb_define_singleton_method(mXmlhash, "parse_int", &parse_xml_hash, 1);
|
data/lib/xmlhash.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'xmlhash/xmlhash'
|
2
2
|
|
3
3
|
module Xmlhash
|
4
|
-
VERSION = '1.3.
|
4
|
+
VERSION = '1.3.8'
|
5
5
|
|
6
6
|
class XMLHash < Hash
|
7
7
|
|
@@ -65,8 +65,7 @@ module Xmlhash
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def self.parse(str)
|
68
|
-
|
69
|
-
@@mutex.synchronize { parse_int(str) }
|
68
|
+
parse_int(str)
|
70
69
|
end
|
71
70
|
|
72
71
|
end
|
data/test/test_xmlhash.rb
CHANGED
@@ -1,53 +1,51 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "minitest/autorun"
|
4
4
|
require "xmlhash"
|
5
5
|
require 'json'
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
<
|
23
|
-
|
24
|
-
|
25
|
-
</
|
6
|
+
require 'thread'
|
7
|
+
|
8
|
+
Minitest::Test.make_my_diffs_pretty!
|
9
|
+
|
10
|
+
Xml = <<~eos
|
11
|
+
<request id="93651">
|
12
|
+
<action type="submit">
|
13
|
+
<source project="server:dns" package="pdns" rev="65"/>
|
14
|
+
<target project="openSUSE:Factory" package="pdns"/>
|
15
|
+
</action>
|
16
|
+
<state name="revoked" who="coolo" when="2011-12-19T13:20:50">
|
17
|
+
<comment/>
|
18
|
+
</state>
|
19
|
+
<review state="accepted" by_group="legal-auto" who="licensedigger" when="2011-11-25T15:09:55">
|
20
|
+
<comment>Big comment</comment>
|
21
|
+
</review>
|
22
|
+
<review state="new" by_group="factory-auto"/>
|
23
|
+
<history name="review" who="coolo" when="2011-11-25T15:02:53"/>
|
24
|
+
<history name="declined" who="coolo" when="2011-11-25T16:17:30">
|
25
|
+
<comment>please make sure to wait before these depencencies are in openSUSE:Factory: libopendbx-devel, libopendbx1, libopendbxplus1, opendbx-backend-pgsql</comment>
|
26
|
+
</history>
|
27
|
+
<description>update and factory fix (forwarded request 86230 from -miska-)</description>
|
28
|
+
</request>
|
26
29
|
eos
|
27
30
|
|
28
|
-
Output = {"history" =>
|
29
|
-
[{"name" => "review", "when" => "2011-11-25T15:02:53", "who" => "coolo"},
|
30
|
-
{"comment" => "please make sure to wait before these depencencies are in openSUSE:Factory: libopendbx-devel, libopendbx1, libopendbxplus1, opendbx-backend-pgsql",
|
31
|
-
|
32
|
-
|
33
|
-
"review" =>
|
31
|
+
Output = { "history" =>
|
32
|
+
[{ "name" => "review", "when" => "2011-11-25T15:02:53", "who" => "coolo" },
|
33
|
+
{ "comment" => "please make sure to wait before these depencencies are in openSUSE:Factory: libopendbx-devel, libopendbx1, libopendbxplus1, opendbx-backend-pgsql",
|
34
|
+
"name" => "declined", "when" => "2011-11-25T16:17:30", "who" => "coolo" }],
|
35
|
+
"review" =>
|
34
36
|
[
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
class TestXmlhash < Test::Unit::TestCase
|
37
|
+
{ "comment" => "Big comment",
|
38
|
+
"by_group" => "legal-auto",
|
39
|
+
"when" => "2011-11-25T15:09:55",
|
40
|
+
"who" => "licensedigger",
|
41
|
+
"state" => "accepted" },
|
42
|
+
{ "by_group" => "factory-auto",
|
43
|
+
"state" => "new" }
|
44
|
+
], "action" => { "type" => "submit", "target" => { "project" => "openSUSE:Factory", "package" => "pdns" }, "source" => { "rev" => "65", "project" => "server:dns", "package" => "pdns" } }, "id" => "93651", "description" => "update and factory fix (forwarded request 86230 from -miska-)", "state" => { "comment" => {}, "name" => "revoked", "when" => "2011-12-19T13:20:50", "who" => "coolo" } }
|
45
|
+
|
46
|
+
class TestXmlhash < Minitest::Test
|
47
47
|
def test_xml
|
48
|
-
|
49
|
-
|
50
|
-
1000.times {
|
48
|
+
1000.times { |i|
|
51
49
|
ret = Xmlhash.parse(Xml)
|
52
50
|
GC.start
|
53
51
|
assert_equal ret, Output
|
@@ -57,43 +55,45 @@ class TestXmlhash < Test::Unit::TestCase
|
|
57
55
|
ret = Xmlhash.parse(Xml)
|
58
56
|
assert_equal ret, Output
|
59
57
|
}
|
60
|
-
|
61
58
|
end
|
62
59
|
|
63
60
|
def test_threading
|
64
|
-
10
|
65
|
-
|
66
|
-
|
61
|
+
counter = Array.new(10, 100)
|
62
|
+
threads = []
|
63
|
+
10.times do |t|
|
64
|
+
threads << Thread.new do
|
65
|
+
while counter[t] > 0 do
|
67
66
|
ret = Xmlhash.parse(Xml)
|
67
|
+
counter[t] -= 1
|
68
68
|
assert_equal ret, Output
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
72
|
+
threads.each { |thr| thr.join }
|
72
73
|
end
|
73
74
|
|
74
75
|
def test_entry
|
75
|
-
xml =
|
76
|
-
<?xml version='1.0' encoding='UTF-8'?>
|
77
|
-
<directory count="4">
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
</directory>
|
83
|
-
eos
|
84
|
-
|
85
|
-
rubyoutput = {"count" => "4",
|
86
|
-
|
87
|
-
[{"name" => "Apache"},
|
88
|
-
{"name" => "Apache:APR_Pool_Debug"},
|
89
|
-
{"name" => "Apache:MirrorBrain"},
|
90
|
-
{"name" => "Apache:Modules"}]}
|
76
|
+
xml = <<~eos
|
77
|
+
<?xml version='1.0' encoding='UTF-8'?>
|
78
|
+
<directory count="4">
|
79
|
+
<entry name="Apache"/>
|
80
|
+
<entry name="Apache:APR_Pool_Debug"/>
|
81
|
+
<entry name="Apache:MirrorBrain"/>
|
82
|
+
<entry name="Apache:Modules"/>
|
83
|
+
</directory>
|
84
|
+
eos
|
85
|
+
|
86
|
+
rubyoutput = { "count" => "4",
|
87
|
+
"entry" =>
|
88
|
+
[{ "name" => "Apache" },
|
89
|
+
{ "name" => "Apache:APR_Pool_Debug" },
|
90
|
+
{ "name" => "Apache:MirrorBrain" },
|
91
|
+
{ "name" => "Apache:Modules" }] }
|
91
92
|
|
92
93
|
ret = Xmlhash.parse(xml)
|
93
94
|
assert_equal ret, rubyoutput
|
94
95
|
|
95
96
|
assert_equal ret.elements("entry").first.value("name"), "Apache"
|
96
|
-
|
97
97
|
end
|
98
98
|
|
99
99
|
def test_encoding
|
@@ -104,21 +104,21 @@ eos
|
|
104
104
|
|
105
105
|
xml = "<?xml version='1.0' encoding='UTF-8'?><name value='Adrian Schröter'/>"
|
106
106
|
ret = Xmlhash.parse(xml)
|
107
|
-
assert_equal ret, {"value" => "Adrian Schröter"}
|
107
|
+
assert_equal ret, { "value" => "Adrian Schröter" }
|
108
108
|
|
109
109
|
assert_equal ret.get("value"), "Adrian Schröter"
|
110
110
|
end
|
111
111
|
|
112
112
|
def test_cdata
|
113
|
-
xml =
|
114
|
-
<sourcediff key="7ebf6606bf56a9f952dda73f0d861738">
|
115
|
-
|
116
|
-
|
117
|
-
</sourcediff>
|
118
|
-
eos
|
113
|
+
xml = <<~eos
|
114
|
+
<sourcediff key="7ebf6606bf56a9f952dda73f0d861738">
|
115
|
+
<new name="myfile" md5="299d8fe34c516b078c3d367e3fb460b9" size="12"/>
|
116
|
+
<diff lines="1">DummyContent</diff>
|
117
|
+
</sourcediff>
|
118
|
+
eos
|
119
119
|
|
120
120
|
ret = Xmlhash.parse(xml)
|
121
|
-
assert_equal ret['diff'], {"lines" => "1", "_content" => "DummyContent"}
|
121
|
+
assert_equal ret['diff'], { "lines" => "1", "_content" => "DummyContent" }
|
122
122
|
end
|
123
123
|
|
124
124
|
def test_empty
|
@@ -130,7 +130,12 @@ eos
|
|
130
130
|
def test_garbage
|
131
131
|
# unfortunately it's rather challening testing nothing is printed to stderr
|
132
132
|
ret = Xmlhash.parse("asdasdaskdladka")
|
133
|
-
|
133
|
+
assert_nil ret
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_entities
|
137
|
+
ret = Xmlhash.parse("<ents><text><</text><text>></text></ents>")
|
138
|
+
assert_equal ret, {"text"=>["<", ">"]}
|
134
139
|
end
|
135
140
|
|
136
141
|
def test_utf8
|
@@ -161,6 +166,5 @@ The library includes bindings for both the C and C++ languages. It works on POSI
|
|
161
166
|
xml.encode!('US-ASCII')
|
162
167
|
xh = Xmlhash.parse(xml)
|
163
168
|
assert_equal "UTF-8", xh['title'].encoding.to_s
|
164
|
-
|
165
169
|
end
|
166
170
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xmlhash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephan Kulow
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pkg-config
|
@@ -25,47 +25,53 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rake-compiler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rdoc
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '4.0'
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '7'
|
48
51
|
type: :development
|
49
52
|
prerelease: false
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
51
54
|
requirements:
|
52
55
|
- - ">="
|
53
56
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
57
|
+
version: '4.0'
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '7'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: hoe
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
65
|
- - "~>"
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version: '3.
|
67
|
+
version: '3.23'
|
62
68
|
type: :development
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
72
|
- - "~>"
|
67
73
|
- !ruby/object:Gem::Version
|
68
|
-
version: '3.
|
74
|
+
version: '3.23'
|
69
75
|
description: |-
|
70
76
|
A small C module that wraps libxml2's xmlreader to parse a XML
|
71
77
|
string into a ruby hash
|
@@ -93,8 +99,9 @@ files:
|
|
93
99
|
homepage: https://github.com/coolo/xmlhash
|
94
100
|
licenses:
|
95
101
|
- MIT
|
96
|
-
metadata:
|
97
|
-
|
102
|
+
metadata:
|
103
|
+
homepage_uri: https://github.com/coolo/xmlhash
|
104
|
+
post_install_message:
|
98
105
|
rdoc_options:
|
99
106
|
- "--main"
|
100
107
|
- README.txt
|
@@ -111,9 +118,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
118
|
- !ruby/object:Gem::Version
|
112
119
|
version: '0'
|
113
120
|
requirements: []
|
114
|
-
|
115
|
-
|
116
|
-
signing_key:
|
121
|
+
rubygems_version: 3.3.7
|
122
|
+
signing_key:
|
117
123
|
specification_version: 4
|
118
124
|
summary: A small C module that wraps libxml2's xmlreader to parse a XML string into
|
119
125
|
a ruby hash
|