ox 2.4.9 → 2.4.11

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ox might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a56bbf70fe5530b8c2903e35d16657dcc0a6ef1
4
- data.tar.gz: bacb6b71b651b78e43ac8b6aee16cf5e9f9dbfbb
3
+ metadata.gz: 7ef3dbf669a441dbf51b4ada1d623d7ec1415635
4
+ data.tar.gz: 3506603ae57a7f269f0768ce73fd9ce85d3f05d9
5
5
  SHA512:
6
- metadata.gz: 153eb27970aff8e5fd2ada7a2e954578bb1596f5ed7d59bd263cc61c77d7fa0b60375a5bdfae71dc54524ca0119c598abdb8120db7b71dc662fe5a953d39a4ec
7
- data.tar.gz: e96032e02c813895c23e53642600f3083a4ebd2684dd0511e0b1f44ba7743da3e75516921af84f21f4885e0d0db859daf62818b039253b8500983b475a6b0a17
6
+ metadata.gz: a94260a278ae05c25fadb1c1d8e318caf54775eb475e58b7377b939f48870156936a0ed18c81d2e9d46f81df7aaeeaa387f06156b31b4a4b5f4cf5fab38d8e07
7
+ data.tar.gz: 2b674e07e92d615313da5a46a319c8d905447795e3d623b3286a6bff0cccf8997bfdd56b02bd82e42fc0209032d1d6854436f07da6954a0dee3e1218f71c5db8
data/README.md CHANGED
@@ -34,14 +34,7 @@ A fast XML parser and Object marshaller as a Ruby gem.
34
34
 
35
35
  ## Release Notes
36
36
 
37
- ### Release 2.4.8
38
-
39
- - Tolerant mode now allows case-insensitve matches on elements during
40
- parsing. Smart mode in the SAX parser is also case insensitive.
41
-
42
- ### Release 2.4.7
43
-
44
- - After encountering a <> the SAX parser will continue parsing after reporting an error.
37
+ See [CHANGELOG.md](CHANGELOG.md)
45
38
 
46
39
  ## Description
47
40
 
data/ext/ox/builder.c CHANGED
@@ -39,7 +39,7 @@ static const char indent_spaces[] = "\n
39
39
 
40
40
  // The : character is equivalent to 10. Used for replacement characters up to 10
41
41
  // characters long such as '&#x10FFFF;'.
42
- static char xml_friendly_chars[257] = "\
42
+ static const char xml_friendly_chars[257] = "\
43
43
  :::::::::11::1::::::::::::::::::\
44
44
  11611156111111111111111111114141\
45
45
  11111111111111111111111111111111\
@@ -49,12 +49,32 @@ static char xml_friendly_chars[257] = "\
49
49
  11111111111111111111111111111111\
50
50
  11111111111111111111111111111111";
51
51
 
52
+ static const char xml_quote_chars[257] = "\
53
+ :::::::::11::1::::::::::::::::::\
54
+ 11611151111111111111111111111111\
55
+ 11111111111111111111111111111111\
56
+ 11111111111111111111111111111111\
57
+ 11111111111111111111111111111111\
58
+ 11111111111111111111111111111111\
59
+ 11111111111111111111111111111111\
60
+ 11111111111111111111111111111111";
61
+
62
+ static const char xml_element_chars[257] = "\
63
+ :::::::::11::1::::::::::::::::::\
64
+ 11111151111111111111111111114141\
65
+ 11111111111111111111111111111111\
66
+ 11111111111111111111111111111111\
67
+ 11111111111111111111111111111111\
68
+ 11111111111111111111111111111111\
69
+ 11111111111111111111111111111111\
70
+ 11111111111111111111111111111111";
71
+
52
72
  inline static size_t
53
- xml_str_len(const unsigned char *str, size_t len) {
73
+ xml_str_len(const unsigned char *str, size_t len, const char *table) {
54
74
  size_t size = 0;
55
75
 
56
76
  for (; 0 < len; str++, len--) {
57
- size += xml_friendly_chars[*str];
77
+ size += table[*str];
58
78
  }
59
79
  return size - len * (size_t)'0';
60
80
  }
@@ -78,8 +98,8 @@ append_indent(Builder b) {
78
98
  }
79
99
 
80
100
  static void
81
- append_string(Builder b, const char *str, size_t size) {
82
- size_t xsize = xml_str_len((const unsigned char*)str, size);
101
+ append_string(Builder b, const char *str, size_t size, const char *table) {
102
+ size_t xsize = xml_str_len((const unsigned char*)str, size, table);
83
103
 
84
104
  if (size == xsize) {
85
105
  const char *s = str;
@@ -102,7 +122,7 @@ append_string(Builder b, const char *str, size_t size) {
102
122
  int fcnt;
103
123
 
104
124
  for (; '\0' != *str && 0 < i; i--, str++) {
105
- if ('1' == (fcnt = xml_friendly_chars[(unsigned char)*str])) {
125
+ if ('1' == (fcnt = table[(unsigned char)*str])) {
106
126
  if (end <= bp) {
107
127
  buf_append_string(&b->buf, buf, bp - buf);
108
128
  bp = buf;
@@ -170,7 +190,7 @@ append_sym_str(Builder b, VALUE v) {
170
190
  rb_raise(ox_arg_error_class, "expected a Symbol or String");
171
191
  break;
172
192
  }
173
- append_string(b, s, len);
193
+ append_string(b, s, len, xml_element_chars);
174
194
  }
175
195
 
176
196
  static void
@@ -200,7 +220,7 @@ append_attr(VALUE key, VALUE value, Builder b) {
200
220
  b->col += 2;
201
221
  b->pos += 2;
202
222
  Check_Type(value, T_STRING);
203
- append_string(b, StringValuePtr(value), (int)RSTRING_LEN(value));
223
+ append_string(b, StringValuePtr(value), (int)RSTRING_LEN(value), xml_quote_chars);
204
224
  buf_append(&b->buf, '"');
205
225
  b->col++;
206
226
  b->pos++;
@@ -243,7 +263,7 @@ pop(Builder b) {
243
263
  Element e;
244
264
 
245
265
  if (0 > b->depth) {
246
- rb_raise(ox_arg_error_class, "closed to many element");
266
+ rb_raise(ox_arg_error_class, "closed too many elements");
247
267
  }
248
268
  e = &b->stack[b->depth];
249
269
  b->depth--;
@@ -611,7 +631,7 @@ builder_element(int argc, VALUE *argv, VALUE self) {
611
631
  buf_append(&b->buf, '<');
612
632
  b->col++;
613
633
  b->pos++;
614
- append_string(b, e->name, len);
634
+ append_string(b, e->name, len, xml_element_chars);
615
635
  if (1 < argc) {
616
636
  rb_hash_foreach(argv[1], append_attr, (VALUE)b);
617
637
  }
@@ -638,7 +658,7 @@ builder_comment(VALUE self, VALUE text) {
638
658
  buf_append_string(&b->buf, "<!-- ", 5);
639
659
  b->col += 5;
640
660
  b->pos += 5;
641
- append_string(b, StringValuePtr(text), RSTRING_LEN(text));
661
+ append_string(b, StringValuePtr(text), RSTRING_LEN(text), xml_element_chars);
642
662
  buf_append_string(&b->buf, " --/> ", 5);
643
663
  b->col += 5;
644
664
  b->pos += 5;
@@ -661,7 +681,7 @@ builder_doctype(VALUE self, VALUE text) {
661
681
  buf_append_string(&b->buf, "<!DOCTYPE ", 10);
662
682
  b->col += 10;
663
683
  b->pos += 10;
664
- append_string(b, StringValuePtr(text), RSTRING_LEN(text));
684
+ append_string(b, StringValuePtr(text), RSTRING_LEN(text), xml_element_chars);
665
685
  buf_append(&b->buf, '>');
666
686
  b->col++;
667
687
  b->pos++;
@@ -683,7 +703,7 @@ builder_text(VALUE self, VALUE text) {
683
703
  v = rb_funcall(v, ox_to_s_id, 0);
684
704
  }
685
705
  i_am_a_child(b, true);
686
- append_string(b, StringValuePtr(v), RSTRING_LEN(v));
706
+ append_string(b, StringValuePtr(v), RSTRING_LEN(v), xml_element_chars);
687
707
 
688
708
  return Qnil;
689
709
  }
data/ext/ox/dump.c CHANGED
@@ -66,7 +66,7 @@ static void dump_end(Out out, Element e);
66
66
  static void grow(Out out, size_t len);
67
67
 
68
68
  static void dump_value(Out out, const char *value, size_t size);
69
- static void dump_str_value(Out out, const char *value, size_t size);
69
+ static void dump_str_value(Out out, const char *value, size_t size, const char *table);
70
70
  static int dump_var(ID key, VALUE value, Out out);
71
71
  static void dump_num(Out out, VALUE obj);
72
72
  static void dump_date(Out out, VALUE obj);
@@ -74,13 +74,13 @@ static void dump_time_thin(Out out, VALUE obj);
74
74
  static void dump_time_xsd(Out out, VALUE obj);
75
75
  static int dump_hash(VALUE key, VALUE value, Out out);
76
76
 
77
- static int is_xml_friendly(const uchar *str, int len);
77
+ static int is_xml_friendly(const uchar *str, int len, const char *table);
78
78
 
79
79
  static const char hex_chars[17] = "0123456789abcdef";
80
80
 
81
81
  // The : character is equivalent to 10. Used for replacement characters up to 10
82
82
  // characters long such as '&#x10FFFF;'.
83
- static char xml_friendly_chars[257] = "\
83
+ static const char xml_friendly_chars[257] = "\
84
84
  :::::::::11::1::::::::::::::::::\
85
85
  11611156111111111111111111114141\
86
86
  11111111111111111111111111111111\
@@ -90,10 +90,30 @@ static char xml_friendly_chars[257] = "\
90
90
  11111111111111111111111111111111\
91
91
  11111111111111111111111111111111";
92
92
 
93
+ static const char xml_quote_chars[257] = "\
94
+ :::::::::11::1::::::::::::::::::\
95
+ 11611151111111111111111111111111\
96
+ 11111111111111111111111111111111\
97
+ 11111111111111111111111111111111\
98
+ 11111111111111111111111111111111\
99
+ 11111111111111111111111111111111\
100
+ 11111111111111111111111111111111\
101
+ 11111111111111111111111111111111";
102
+
103
+ static const char xml_element_chars[257] = "\
104
+ :::::::::11::1::::::::::::::::::\
105
+ 11111151111111111111111111114141\
106
+ 11111111111111111111111111111111\
107
+ 11111111111111111111111111111111\
108
+ 11111111111111111111111111111111\
109
+ 11111111111111111111111111111111\
110
+ 11111111111111111111111111111111\
111
+ 11111111111111111111111111111111";
112
+
93
113
  inline static int
94
- is_xml_friendly(const uchar *str, int len) {
114
+ is_xml_friendly(const uchar *str, int len, const char *table) {
95
115
  for (; 0 < len; str++, len--) {
96
- if ('1' != xml_friendly_chars[*str]) {
116
+ if ('1' != table[*str]) {
97
117
  return 0;
98
118
  }
99
119
  }
@@ -101,7 +121,7 @@ is_xml_friendly(const uchar *str, int len) {
101
121
  }
102
122
 
103
123
  inline static size_t
104
- xml_str_len(const uchar *str, size_t len) {
124
+ xml_str_len(const uchar *str, size_t len, const char *table) {
105
125
  size_t size = 0;
106
126
 
107
127
  for (; 0 < len; str++, len--) {
@@ -131,12 +151,12 @@ obj_class_code(VALUE obj) {
131
151
  case T_FALSE: return FalseClassCode;
132
152
  case T_FIXNUM: return FixnumCode;
133
153
  case T_FLOAT: return FloatCode;
134
- case T_STRING: return (is_xml_friendly((uchar*)StringValuePtr(obj), (int)RSTRING_LEN(obj))) ? StringCode : String64Code;
154
+ case T_STRING: return (is_xml_friendly((uchar*)StringValuePtr(obj), (int)RSTRING_LEN(obj), xml_element_chars)) ? StringCode : String64Code;
135
155
  case T_SYMBOL:
136
156
  {
137
157
  const char *sym = rb_id2name(SYM2ID(obj));
138
158
 
139
- return (is_xml_friendly((uchar*)sym, (int)strlen(sym))) ? SymbolCode : Symbol64Code;
159
+ return (is_xml_friendly((uchar*)sym, (int)strlen(sym), xml_element_chars)) ? SymbolCode : Symbol64Code;
140
160
  }
141
161
  case T_DATA: return (rb_cTime == clas) ? TimeCode : ((ox_date_class == clas) ? DateCode : 0);
142
162
  case T_STRUCT: return (rb_cRange == clas) ? RangeCode : StructCode;
@@ -319,14 +339,14 @@ dump_value(Out out, const char *value, size_t size) {
319
339
  }
320
340
 
321
341
  inline static void
322
- dump_str_value(Out out, const char *value, size_t size) {
323
- size_t xsize = xml_str_len((const uchar*)value, size);
342
+ dump_str_value(Out out, const char *value, size_t size, const char *table) {
343
+ size_t xsize = xml_str_len((const uchar*)value, size, table);
324
344
 
325
345
  if (out->end - out->cur <= (long)xsize) {
326
346
  grow(out, xsize);
327
347
  }
328
348
  for (; '\0' != *value; value++) {
329
- if ('1' == xml_friendly_chars[(uchar)*value]) {
349
+ if ('1' == table[(uchar)*value]) {
330
350
  *out->cur++ = *value;
331
351
  } else {
332
352
  switch (*value) {
@@ -685,7 +705,7 @@ dump_obj(ID aid, VALUE obj, int depth, Out out) {
685
705
  if (is_xml_friendly((uchar*)str, cnt)) {
686
706
  e.type = StringCode;
687
707
  out->w_start(out, &e);
688
- dump_str_value(out, str, cnt);
708
+ dump_str_value(out, str, cnt, '<');
689
709
  e.indent = -1;
690
710
  out->w_end(out, &e);
691
711
  } else {
@@ -702,7 +722,7 @@ dump_obj(ID aid, VALUE obj, int depth, Out out) {
702
722
  #else
703
723
  e.type = StringCode;
704
724
  out->w_start(out, &e);
705
- dump_str_value(out, str, cnt);
725
+ dump_str_value(out, str, cnt, xml_element_chars);
706
726
  e.indent = -1;
707
727
  out->w_end(out, &e);
708
728
  #endif
@@ -717,7 +737,7 @@ dump_obj(ID aid, VALUE obj, int depth, Out out) {
717
737
  if (is_xml_friendly((uchar*)sym, cnt)) {
718
738
  e.type = SymbolCode;
719
739
  out->w_start(out, &e);
720
- dump_str_value(out, sym, cnt);
740
+ dump_str_value(out, sym, cnt, '<');
721
741
  e.indent = -1;
722
742
  out->w_end(out, &e);
723
743
  } else {
@@ -734,7 +754,7 @@ dump_obj(ID aid, VALUE obj, int depth, Out out) {
734
754
  #else
735
755
  e.type = SymbolCode;
736
756
  out->w_start(out, &e);
737
- dump_str_value(out, sym, cnt);
757
+ dump_str_value(out, sym, cnt, xml_element_chars);
738
758
  e.indent = -1;
739
759
  out->w_end(out, &e);
740
760
  #endif
@@ -901,7 +921,7 @@ dump_obj(ID aid, VALUE obj, int depth, Out out) {
901
921
  #if USE_B64
902
922
  if (is_xml_friendly((uchar*)s, cnt)) {
903
923
  /*dump_value(out, "/", 1); */
904
- dump_str_value(out, s, cnt);
924
+ dump_str_value(out, s, cnt, '<');
905
925
  } else {
906
926
  ulong size = b64_size(cnt);
907
927
  char *b64 = ALLOCA_N(char, size + 1);
@@ -910,7 +930,7 @@ dump_obj(ID aid, VALUE obj, int depth, Out out) {
910
930
  dump_value(out, b64, size);
911
931
  }
912
932
  #else
913
- dump_str_value(out, s, cnt);
933
+ dump_str_value(out, s, cnt, xml_element_chars);
914
934
  #endif
915
935
  e.indent = -1;
916
936
  out->w_end(out, &e);
@@ -1148,7 +1168,7 @@ dump_gen_nodes(VALUE obj, int depth, Out out) {
1148
1168
  dump_gen_instruct(*np, d2, out);
1149
1169
  indent_needed = (1 == cnt) ? 0 : 1;
1150
1170
  } else if (rb_cString == clas) {
1151
- dump_str_value(out, StringValuePtr(*(VALUE*)np), RSTRING_LEN(*np));
1171
+ dump_str_value(out, StringValuePtr(*(VALUE*)np), RSTRING_LEN(*np), xml_element_chars);
1152
1172
  indent_needed = (1 == cnt) ? 0 : 1;
1153
1173
  } else if (ox_comment_clas == clas) {
1154
1174
  dump_gen_val_node(*np, d2, "<!-- ", 5, " -->", 4, out);
@@ -1200,7 +1220,7 @@ dump_gen_attr(VALUE key, VALUE value, Out out) {
1200
1220
  fill_value(out, ks, klen);
1201
1221
  *out->cur++ = '=';
1202
1222
  *out->cur++ = '"';
1203
- dump_str_value(out, StringValuePtr(value), RSTRING_LEN(value));
1223
+ dump_str_value(out, StringValuePtr(value), RSTRING_LEN(value), xml_quote_chars);
1204
1224
  *out->cur++ = '"';
1205
1225
 
1206
1226
  return ST_CONTINUE;
data/ext/ox/sax.c CHANGED
@@ -3,6 +3,7 @@
3
3
  * All rights reserved.
4
4
  */
5
5
 
6
+ #include <ctype.h>
6
7
  #include <stdlib.h>
7
8
  #include <errno.h>
8
9
  #include <stdio.h>
@@ -985,7 +986,7 @@ read_element_start(SaxDrive dr) {
985
986
  end_element_cb(dr, name, pos, line, col, h);
986
987
  } else if (stackless) {
987
988
  end_element_cb(dr, name, pos, line, col, h);
988
- } else if (0 != h && h->jump) {
989
+ } else if (NULL != h && h->jump) {
989
990
  stack_push(&dr->stack, ename, name, h);
990
991
  if ('>' != c) {
991
992
  ox_sax_drive_error(dr, WRONG_CHAR "element not closed");
@@ -1224,11 +1225,11 @@ read_jump_term(Buf buf, const char *pat) {
1224
1225
  if ('/' != buf_next_non_white(buf)) {
1225
1226
  return 0;
1226
1227
  }
1227
- if (*pat != buf_next_non_white(buf)) {
1228
+ if (*pat != tolower(buf_next_non_white(buf))) {
1228
1229
  return 0;
1229
1230
  }
1230
1231
  for (pat++; '\0' != *pat; pat++) {
1231
- if (*pat != buf_get(buf)) {
1232
+ if (*pat != tolower(buf_get(buf))) {
1232
1233
  return 0;
1233
1234
  }
1234
1235
  }
data/lib/ox/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Ox
3
3
  # Current version of the module.
4
- VERSION = '2.4.9'
4
+ VERSION = '2.4.11'
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.4.9
4
+ version: 2.4.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-25 00:00:00.000000000 Z
11
+ date: 2017-03-19 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
14
14
  \ \nOptimized XML (Ox), as the name implies was written to provide speed
@@ -102,4 +102,3 @@ signing_key:
102
102
  specification_version: 4
103
103
  summary: A fast XML parser and object serializer.
104
104
  test_files: []
105
- has_rdoc: true