xmlhash 1.3.7 → 1.3.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 73463ec5fefb712dcc460538b6ce8bfd1f8f3997
4
- data.tar.gz: 130a50fad1c5ac6ce9926e8ad21e6dc702bf3b57
2
+ SHA256:
3
+ metadata.gz: 3f72be19a08e60ff2efe59afb44753d23f3bb9eea969e98c6dbb80e03df376a8
4
+ data.tar.gz: e1114dead31f0e4ecedf639a22dac1f114ba136f21875183b35a65dd88867e5b
5
5
  SHA512:
6
- metadata.gz: dc044eb3f72bb781c81ffd1f1117e2cd49ca936ce7cc6eee81ea8884d8be1f7c6c4466c0d3a5c99090c4e773bfa66e72b1b1f4687836071c9db3c6958ed91697
7
- data.tar.gz: 6a1355488594f5c9f0560b9a3a13a3c0b3e121efc6d03794f5b8b8a2984c9ebc9d57aec57283e13ac0bfaef588be23c21a43a69119c33c363bd2b0010a09c4d5
6
+ metadata.gz: c57699c0ca0943c498b154dfefd9d9e2039fd05daf19427852417b634dd364b75c0f03280e0017ea1da04745684e82e19d68176ef3382c864db111c9dfb292c2
7
+ data.tar.gz: fb8689064ee31b7dcd827682ac0d25bbc1b7c8eed41284118d283ec6aecd59a076e984d37c9539b3dbbd70fdd8b75f940743004cc86fe1846c9e86fa5fcd2606
data/Gemfile CHANGED
@@ -4,3 +4,4 @@ gem 'hoe'
4
4
  gem 'rake-compiler'
5
5
  gem 'pkg-config'
6
6
  gem 'json'
7
+ gem 'minitest', '>= 5.0.0', group: :test
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 1.3.8 / 2022-04-04
2
+
3
+ * Do not replace entities while parsing
4
+
1
5
  === 1.3.7 / 2016-07-04
2
6
 
3
7
  * Fix XML parsing: ignore comments and parse huge TXT nodes
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
@@ -4,4 +4,5 @@ unless find_library('xml2', 'xmlAddID')
4
4
  abort "xml2 is missing. please install libxml2"
5
5
  end
6
6
  $CFLAGS << ' ' + PackageConfig.new('libxml-2.0').cflags
7
+ $CFLAGS += " -Werror "
7
8
  create_makefile('xmlhash/xmlhash')
@@ -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, XML_PARSE_NOENT | XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_HUGE );
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.7'
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
- @@mutex ||= Mutex.new
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 "test/unit"
3
+ require "minitest/autorun"
4
4
  require "xmlhash"
5
5
  require 'json'
6
-
7
- Xml = <<eos
8
- <request id="93651">
9
- <action type="submit">
10
- <source project="server:dns" package="pdns" rev="65"/>
11
- <target project="openSUSE:Factory" package="pdns"/>
12
- </action>
13
- <state name="revoked" who="coolo" when="2011-12-19T13:20:50">
14
- <comment/>
15
- </state>
16
- <review state="accepted" by_group="legal-auto" who="licensedigger" when="2011-11-25T15:09:55">
17
- <comment>Big comment</comment>
18
- </review>
19
- <review state="new" by_group="factory-auto"/>
20
- <history name="review" who="coolo" when="2011-11-25T15:02:53"/>
21
- <history name="declined" who="coolo" when="2011-11-25T16:17:30">
22
- <comment>please make sure to wait before these depencencies are in openSUSE:Factory: libopendbx-devel, libopendbx1, libopendbxplus1, opendbx-backend-pgsql</comment>
23
- </history>
24
- <description>update and factory fix (forwarded request 86230 from -miska-)</description>
25
- </request>
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
- "name" => "declined", "when" => "2011-11-25T16:17:30", "who" => "coolo"}
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
- {"comment" => "Big comment",
36
- "by_group" => "legal-auto",
37
- "when" => "2011-11-25T15:09:55",
38
- "who" => "licensedigger",
39
- "state" => "accepted"
40
- },
41
- {"by_group" => "factory-auto",
42
- "state" => "new"}
43
- ], "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"}}
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.times do
65
- Thread.new do
66
- 100.times do
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 = <<eos
76
- <?xml version='1.0' encoding='UTF-8'?>
77
- <directory count="4">
78
- <entry name="Apache"/>
79
- <entry name="Apache:APR_Pool_Debug"/>
80
- <entry name="Apache:MirrorBrain"/>
81
- <entry name="Apache:Modules"/>
82
- </directory>
83
- eos
84
-
85
- rubyoutput = {"count" => "4",
86
- "entry" =>
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 = <<eos
114
- <sourcediff key="7ebf6606bf56a9f952dda73f0d861738">
115
- <new name="myfile" md5="299d8fe34c516b078c3d367e3fb460b9" size="12"/>
116
- <diff lines="1">DummyContent</diff>
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
- assert_equal nil, ret
133
+ assert_nil ret
134
+ end
135
+
136
+ def test_entities
137
+ ret = Xmlhash.parse("<ents><text>&lt;</text><text>&gt;</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.7
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: 2016-07-04 00:00:00.000000000 Z
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: rdoc
28
+ name: rake-compiler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '4.0'
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: '4.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake-compiler
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.15'
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.15'
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
- post_install_message:
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
- rubyforge_project:
115
- rubygems_version: 2.4.5.1
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