ox 2.13.4 → 2.14.0

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
2
  SHA256:
3
- metadata.gz: 455a3e6630c8cf482656e024c14c609cfcc5441d201dd6b6f7649a283309bf87
4
- data.tar.gz: e6240807c3f21f2915d044b56bc05433730a39315b10a50c3698adcc5640cf1d
3
+ metadata.gz: '059b3f1db82648104560fe8087b57d8c7e1ee082ed953a53afcdf3f8762b0a3e'
4
+ data.tar.gz: 344eac455d082e55935804cc45a7f399ebce83be700c1895a4679f28cd3b635a
5
5
  SHA512:
6
- metadata.gz: 3ddfd3e2a3e80338a1f5d4cf36b9b0ea28b721f24d7d6bc8c3b1a27c2c026484596274b105b4da602e4070627411297295807eebbf83cc923863d4494e0c0c32
7
- data.tar.gz: af3b468beb6e48aa6046b3829ee186433be56d308dd3bb06b19068eefd4a315c004353aaa245a95fdc42d315e817d7cca4f3d309b745fb782c5e77bbd463e427
6
+ metadata.gz: f4a109a5e5d97594c1c266bfd071af26aedf94acaf08d11c55ea03981fef97bff44d762c3df2b6b21da8559d928e7aac1d6d3421fbe0af56fb2eec10975449a6
7
+ data.tar.gz: c82c7d2ca8fb54eb4f04d7da7b1b5527ef47e89905fcdd3b9ab9b5407bee6c9f3a55ea253472e212810e10cec71627a9cd84dcbb69f1c3db2bdee2e86651f6bd
@@ -4,6 +4,12 @@ All changes to the Ox gem are documented here. Releases follow semantic versioni
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [2.14.0] - 2020-12-15
8
+
9
+ ### Added
10
+
11
+ - The `:with_cdata` option added for the hash_load() function.
12
+
7
13
  ## [2.13.4] - 2020-09-11
8
14
 
9
15
  ### Fixed
@@ -74,9 +74,8 @@ unmark(PInfo pi, VALUE val) {
74
74
  }
75
75
 
76
76
  static void
77
- add_text(PInfo pi, char *text, int closed) {
77
+ add_str(PInfo pi, VALUE s) {
78
78
  Helper parent = helper_stack_peek(&pi->helpers);
79
- volatile VALUE s = rb_str_new2(text);
80
79
  volatile VALUE a;
81
80
 
82
81
  #if HAVE_RB_ENC_ASSOCIATE
@@ -102,6 +101,16 @@ add_text(PInfo pi, char *text, int closed) {
102
101
  }
103
102
  }
104
103
 
104
+ static void
105
+ add_text(PInfo pi, char *text, int closed) {
106
+ add_str(pi, rb_str_new2(text));
107
+ }
108
+
109
+ static void
110
+ add_cdata(PInfo pi, const char *text, size_t len) {
111
+ add_str(pi, rb_str_new(text, len));
112
+ }
113
+
105
114
  static void
106
115
  add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren) {
107
116
  if (helper_stack_empty(&pi->helpers)) {
@@ -250,6 +259,19 @@ struct _parseCallbacks _ox_hash_callbacks = {
250
259
 
251
260
  ParseCallbacks ox_hash_callbacks = &_ox_hash_callbacks;
252
261
 
262
+ struct _parseCallbacks _ox_hash_cdata_callbacks = {
263
+ NULL,
264
+ NULL,
265
+ NULL,
266
+ add_cdata,
267
+ add_text,
268
+ add_element,
269
+ end_element,
270
+ finish,
271
+ };
272
+
273
+ ParseCallbacks ox_hash_cdata_callbacks = &_ox_hash_cdata_callbacks;
274
+
253
275
  struct _parseCallbacks _ox_hash_no_attrs_callbacks = {
254
276
  NULL,
255
277
  NULL,
@@ -262,3 +284,16 @@ struct _parseCallbacks _ox_hash_no_attrs_callbacks = {
262
284
  };
263
285
 
264
286
  ParseCallbacks ox_hash_no_attrs_callbacks = &_ox_hash_no_attrs_callbacks;
287
+
288
+ struct _parseCallbacks _ox_hash_no_attrs_cdata_callbacks = {
289
+ NULL,
290
+ NULL,
291
+ NULL,
292
+ add_cdata,
293
+ add_text,
294
+ add_element_no_attrs,
295
+ end_element_no_attrs,
296
+ NULL,
297
+ };
298
+
299
+ ParseCallbacks ox_hash_no_attrs_cdata_callbacks = &_ox_hash_no_attrs_cdata_callbacks;
@@ -145,6 +145,7 @@ static VALUE symbolize_keys_sym;
145
145
  static VALUE symbolize_sym;
146
146
  static VALUE tolerant_sym;
147
147
  static VALUE trace_sym;
148
+ static VALUE with_cdata_sym;
148
149
  static VALUE with_dtd_sym;
149
150
  static VALUE with_instruct_sym;
150
151
  static VALUE with_xml_sym;
@@ -179,6 +180,7 @@ struct _options ox_default_options = {
179
180
  true, // convert_special
180
181
  No, // allow_invalid
181
182
  false, // no_empty
183
+ false, // with_cdata
182
184
  { '\0' }, // inv_repl
183
185
  { '\0' }, // strip_ns
184
186
  NULL, // html_hints
@@ -192,7 +194,9 @@ extern ParseCallbacks ox_gen_callbacks;
192
194
  extern ParseCallbacks ox_limited_callbacks;
193
195
  extern ParseCallbacks ox_nomode_callbacks;
194
196
  extern ParseCallbacks ox_hash_callbacks;
197
+ extern ParseCallbacks ox_hash_cdata_callbacks;
195
198
  extern ParseCallbacks ox_hash_no_attrs_callbacks;
199
+ extern ParseCallbacks ox_hash_no_attrs_cdata_callbacks;
196
200
 
197
201
  static void parse_dump_options(VALUE ropts, Options copts);
198
202
 
@@ -290,6 +294,7 @@ hints_to_overlay(Hints hints) {
290
294
  * - _:convert_special_ [true|false|nil] flag indicating special characters like < are converted with the SAX parser
291
295
  * - _:invalid_replace_ [nil|String] replacement string for invalid XML characters on dump. nil indicates include anyway as hex. A string, limited to 10 characters will replace the invalid character with the replace.
292
296
  * - _:no_empty_ [true|false|nil] flag indicating there should be no empty elements in a dump
297
+ * - _:with_cdata_ [true|false] includes cdata in hash_load results
293
298
  * - _:strip_namespace_ [String|true|false] false or "" results in no namespace stripping. A string of "*" or true will strip all namespaces. Any other non-empty string indicates that matching namespaces will be stripped.
294
299
  * - _:overlay_ [Hash] a Hash of keys that match html element names and values that are one of
295
300
  * - _:active_ - make the normal callback for the element
@@ -324,6 +329,7 @@ get_def_opts(VALUE self) {
324
329
  rb_hash_aset(opts, smart_sym, (Yes == ox_default_options.smart) ? Qtrue : ((No == ox_default_options.smart) ? Qfalse : Qnil));
325
330
  rb_hash_aset(opts, convert_special_sym, (ox_default_options.convert_special) ? Qtrue : Qfalse);
326
331
  rb_hash_aset(opts, no_empty_sym, (ox_default_options.no_empty) ? Qtrue : Qfalse);
332
+ rb_hash_aset(opts, with_cdata_sym, (ox_default_options.with_cdata) ? Qtrue : Qfalse);
327
333
  switch (ox_default_options.mode) {
328
334
  case ObjMode: rb_hash_aset(opts, mode_sym, object_sym); break;
329
335
  case GenMode: rb_hash_aset(opts, mode_sym, generic_sym); break;
@@ -431,6 +437,7 @@ sax_html_overlay(VALUE self) {
431
437
  * - _:smart_ [true|false|nil] flag indicating the SAX parser uses hints if available (use with html)
432
438
  * - _:invalid_replace_ [nil|String] replacement string for invalid XML characters on dump. nil indicates include anyway as hex. A string, limited to 10 characters will replace the invalid character with the replace.
433
439
  * - _:strip_namespace_ [nil|String|true|false] "" or false result in no namespace stripping. A string of "*" or true will strip all namespaces. Any other non-empty string indicates that matching namespaces will be stripped.
440
+ * - _:with_cdata_ [true|false] includes cdata in hash_load results
434
441
  * - _:overlay_ [Hash] a Hash of keys that match html element names and values that are one of
435
442
  * - _:active_ - make the normal callback for the element
436
443
  * - _:nest_ok_ - active but ignore nest check
@@ -630,6 +637,10 @@ set_def_opts(VALUE self, VALUE opts) {
630
637
  rb_hash_foreach(v, set_overlay, (VALUE)ox_default_options.html_hints);
631
638
  }
632
639
  }
640
+ if (Qnil != (v = rb_hash_lookup(opts, with_cdata_sym))) {
641
+ ox_default_options.with_cdata = (Qtrue == v);
642
+ }
643
+
633
644
  ox_default_options.element_key_mod = rb_hash_lookup2(opts, element_key_mod_sym, ox_default_options.element_key_mod);
634
645
  ox_default_options.attr_key_mod = rb_hash_lookup2(opts, attr_key_mod_sym, ox_default_options.attr_key_mod);
635
646
 
@@ -838,6 +849,9 @@ load(char *xml, size_t len, int argc, VALUE *argv, VALUE self, VALUE encoding, E
838
849
  options.margin[sizeof(options.margin) - 1] = '\0';
839
850
  options.margin_len = strlen(options.margin);
840
851
  }
852
+ if (Qnil != (v = rb_hash_lookup(h, with_cdata_sym))) {
853
+ options.with_cdata = (Qtrue == v);
854
+ }
841
855
  }
842
856
  #if HAVE_RB_ENC_FIND
843
857
  if ('\0' == *options.encoding) {
@@ -869,10 +883,18 @@ load(char *xml, size_t len, int argc, VALUE *argv, VALUE self, VALUE encoding, E
869
883
  obj = ox_parse(xml, len, ox_limited_callbacks, 0, &options, err);
870
884
  break;
871
885
  case HashMode:
872
- obj = ox_parse(xml, len, ox_hash_callbacks, 0, &options, err);
886
+ if (options.with_cdata) {
887
+ obj = ox_parse(xml, len, ox_hash_cdata_callbacks, 0, &options, err);
888
+ } else {
889
+ obj = ox_parse(xml, len, ox_hash_callbacks, 0, &options, err);
890
+ }
873
891
  break;
874
892
  case HashNoAttrMode:
875
- obj = ox_parse(xml, len, ox_hash_no_attrs_callbacks, 0, &options, err);
893
+ if (options.with_cdata) {
894
+ obj = ox_parse(xml, len, ox_hash_no_attrs_cdata_callbacks, 0, &options, err);
895
+ } else {
896
+ obj = ox_parse(xml, len, ox_hash_no_attrs_callbacks, 0, &options, err);
897
+ }
876
898
  break;
877
899
  case NoMode:
878
900
  obj = ox_parse(xml, len, ox_nomode_callbacks, 0, &options, err);
@@ -908,6 +930,7 @@ load(char *xml, size_t len, int argc, VALUE *argv, VALUE self, VALUE encoding, E
908
930
  * - *:symbolize_keys* [true|false|nil] symbolize element attribute keys or leave as Strings
909
931
  * - *:invalid_replace* [nil|String] replacement string for invalid XML characters on dump. nil indicates include anyway as hex. A string, limited to 10 characters will replace the invalid character with the replace.
910
932
  * - *:strip_namespace* [String|true|false] "" or false result in no namespace stripping. A string of "*" or true will strip all namespaces. Any other non-empty string indicates that matching namespaces will be stripped.
933
+ * - *:with_cdata* [true|false] if true cdata is included in hash_load output otherwise it is not.
911
934
  */
912
935
  static VALUE
913
936
  load_str(int argc, VALUE *argv, VALUE self) {
@@ -1516,6 +1539,7 @@ void Init_ox() {
1516
1539
  symbolize_sym = ID2SYM(rb_intern("symbolize")); rb_gc_register_address(&symbolize_sym);
1517
1540
  tolerant_sym = ID2SYM(rb_intern("tolerant")); rb_gc_register_address(&tolerant_sym);
1518
1541
  trace_sym = ID2SYM(rb_intern("trace")); rb_gc_register_address(&trace_sym);
1542
+ with_cdata_sym = ID2SYM(rb_intern("with_cdata")); rb_gc_register_address(&with_cdata_sym);
1519
1543
  with_dtd_sym = ID2SYM(rb_intern("with_dtd")); rb_gc_register_address(&with_dtd_sym);
1520
1544
  with_instruct_sym = ID2SYM(rb_intern("with_instructions")); rb_gc_register_address(&with_instruct_sym);
1521
1545
  with_xml_sym = ID2SYM(rb_intern("with_xml")); rb_gc_register_address(&with_xml_sym);
@@ -136,6 +136,7 @@ typedef struct _options {
136
136
  char convert_special;// boolean true or false
137
137
  char allow_invalid; // YesNo
138
138
  char no_empty; // boolean - no empty elements when dumping
139
+ char with_cdata; // boolean - hash_load should include cdata
139
140
  char inv_repl[12]; // max 10 valid characters, first character is the length
140
141
  char strip_ns[64]; // namespace to strip, \0 is no-strip, \* is all, else only matches
141
142
  struct _hints *html_hints; // html hints
@@ -115,17 +115,8 @@ module Ox
115
115
  # matching name will be yielded to. If the cond is a Hash then the
116
116
  # keys-value pairs in the cond must match the child attribute values with
117
117
  # the same keys. Any other cond type will yield to nothing.
118
- def each(cond=nil)
119
- if cond.nil?
120
- nodes.each { |n| yield(n) }
121
- else
122
- cond = cond.to_s if cond.is_a?(Symbol)
123
- if cond.is_a?(String)
124
- nodes.each { |n| yield(n) if n.is_a?(Element) && cond == n.name }
125
- elsif cond.is_a?(Hash)
126
- nodes.each { |n| yield(n) if n.is_a?(Element) && n.attr_match(cond) }
127
- end
128
- end
118
+ def each(cond=nil, &block)
119
+ build_enumerator(cond).each(&block)
129
120
  end
130
121
 
131
122
  # Returns an array of Nodes or Strings that correspond to the locations
@@ -413,6 +404,24 @@ module Ox
413
404
 
414
405
  private
415
406
 
407
+ # Builds an enumerator for use in `#each` call
408
+ #
409
+ # - +cond+ [Hash, String, nil] an element filter
410
+ def build_enumerator(cond)
411
+ if cond.nil?
412
+ nodes.each
413
+ else
414
+ cond = cond.to_s if cond.is_a?(Symbol)
415
+ Enumerator.new do |yielder|
416
+ if cond.is_a?(String)
417
+ nodes.each { |n| yielder.yield(n) if n.is_a?(Element) && cond == n.name }
418
+ elsif cond.is_a?(Hash)
419
+ nodes.each { |n| yielder.yield(n) if n.is_a?(Element) && n.attr_match(cond) }
420
+ end
421
+ end
422
+ end
423
+ end
424
+
416
425
  # Removes recursively children for nodes and sub_nodes
417
426
  #
418
427
  # - +found+ [Array] An array of Ox::Element
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Ox
3
3
  # Current version of the module.
4
- VERSION = '2.13.4'
4
+ VERSION = '2.14.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ox
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.13.4
4
+ version: 2.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-11 00:00:00.000000000 Z
11
+ date: 2020-12-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: "A fast XML parser and object serializer that uses only standard C lib.\n\nOptimized
14
14
  XML (Ox), as the name implies was written to provide speed optimized\nXML handling.
@@ -76,7 +76,7 @@ homepage: http://www.ohler.com/ox
76
76
  licenses:
77
77
  - MIT
78
78
  metadata: {}
79
- post_install_message:
79
+ post_install_message:
80
80
  rdoc_options:
81
81
  - "--main"
82
82
  - README.md
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  version: '0'
100
100
  requirements: []
101
101
  rubygems_version: 3.1.2
102
- signing_key:
102
+ signing_key:
103
103
  specification_version: 4
104
104
  summary: A fast XML parser and object serializer.
105
105
  test_files: []