oj 2.18.0 → 2.18.1

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
- ---
2
- SHA1:
3
- metadata.gz: 49295a5c6be0e45972d2cf83173fabb2db55fcc3
4
- data.tar.gz: 645d5ec2b8214eeb596fd98cb5a9c0e1e2a9836e
5
- SHA512:
6
- metadata.gz: 0731c01c050cc7aff03be4510be0ad026ed0a320f1fee34fb6318bcdcb5888455c13e9dfb6ec2e7b4d6436e5c04cf43a6d43ff257bb076cc1ec5b8ee5c224cc4
7
- data.tar.gz: ce82256a18f92155498d0ee6b74c06704eb51782cd3411a3c7c2308af252386e668c43216831b32999a349cea83ff5804515314ec1ef9dfc1df36fac388c56dc
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0c4ba43d61f927e22bc0e86fcb053d0593a531f0
4
+ data.tar.gz: d09686c7ff45e8c6b07fd71c7c31aa5c7920a2f3
5
+ SHA512:
6
+ metadata.gz: 1a8f222f85bf299d92f6ea6432d2bae1f541f5ed615e18a052a7328badb430050928a363961fde7148aa66fb56f6507608fe6e17c482f003cb13230073dc58bd
7
+ data.tar.gz: d65f126ff8de728d8a95048ce7f624bf51c3ea81721fb29ad27855454f8c94ba7e971676c3144330a9e93a973e443ed70698247f2c65ffb1be3fbf58863bd07f
data/README.md CHANGED
@@ -170,18 +170,7 @@ Oj.default_options = {:mode => :compat }
170
170
 
171
171
  ## Releases
172
172
 
173
- ** Release 2.18.0**
174
-
175
- - Rubinius compilation fixes.
176
-
177
- - Added a separate option for as_json instead of piggy backing on the
178
- use_to_json. This changes the API slightly.
179
-
180
- - Ready for Ruby 2.4.
181
-
182
- - Thanks to faucct for fixing mimic to not redefine JSON::ParseError.
183
-
184
- [Older release notes](http://www.ohler.com/dev/oj_misc/release_notes.html).
173
+ See [CHANGELOG.md](CHANGELOG.md)
185
174
 
186
175
  ## Compatibility
187
176
 
@@ -867,6 +867,35 @@ get_doc_leaf(Doc doc, const char *path) {
867
867
  return leaf;
868
868
  }
869
869
 
870
+ static const char*
871
+ next_slash(const char *s) {
872
+ for (; '\0' != *s; s++) {
873
+ if ('\\' == *s) {
874
+ s++;
875
+ if ('\0' == *s) {
876
+ break;
877
+ }
878
+ } else if ('/' == *s) {
879
+ return s;
880
+ }
881
+ }
882
+ return NULL;
883
+ }
884
+
885
+ static bool
886
+ key_match(const char *pat, const char *key, int plen) {
887
+ for (; 0 < plen; plen--, pat++, key++) {
888
+ if ('\\' == *pat) {
889
+ plen--;
890
+ pat++;
891
+ }
892
+ if (*pat != *key) {
893
+ return false;
894
+ }
895
+ }
896
+ return '\0' == *key;
897
+ }
898
+
870
899
  static Leaf
871
900
  get_leaf(Leaf *stack, Leaf *lp, const char *path) {
872
901
  Leaf leaf = *lp;
@@ -912,7 +941,7 @@ get_leaf(Leaf *stack, Leaf *lp, const char *path) {
912
941
  } while (e != first);
913
942
  } else if (T_HASH == type) {
914
943
  const char *key = path;
915
- const char *slash = strchr(path, '/');
944
+ const char *slash = next_slash(path);
916
945
  int klen;
917
946
 
918
947
  if (0 == slash) {
@@ -923,7 +952,7 @@ get_leaf(Leaf *stack, Leaf *lp, const char *path) {
923
952
  path += klen + 1;
924
953
  }
925
954
  do {
926
- if (0 == strncmp(key, e->key, klen) && '\0' == e->key[klen]) {
955
+ if (key_match(key, e->key, klen)) {
927
956
  lp++;
928
957
  *lp = e;
929
958
  leaf = get_leaf(stack, lp, path);
@@ -1022,7 +1051,7 @@ move_step(Doc doc, const char *path, int loc) {
1022
1051
  } while (e != first);
1023
1052
  } else if (T_HASH == leaf->rtype) {
1024
1053
  const char *key = path;
1025
- const char *slash = strchr(path, '/');
1054
+ const char *slash = next_slash(path);
1026
1055
  int klen;
1027
1056
 
1028
1057
  if (0 == slash) {
@@ -1033,7 +1062,7 @@ move_step(Doc doc, const char *path, int loc) {
1033
1062
  path += klen + 1;
1034
1063
  }
1035
1064
  do {
1036
- if (0 == strncmp(key, e->key, klen) && '\0' == e->key[klen]) {
1065
+ if (key_match(key, e->key, klen)) {
1037
1066
  doc->where++;
1038
1067
  *doc->where = e;
1039
1068
  loc = move_step(doc, path, loc + 1);
@@ -1167,6 +1196,29 @@ doc_open_file(VALUE clas, VALUE filename) {
1167
1196
  return obj;
1168
1197
  }
1169
1198
 
1199
+ static int
1200
+ esc_strlen(const char *s) {
1201
+ int cnt = 0;
1202
+
1203
+ for (; '\0' != *s; s++, cnt++) {
1204
+ if ('/' == *s) {
1205
+ cnt++;
1206
+ }
1207
+ }
1208
+ return cnt;
1209
+ }
1210
+
1211
+ static char*
1212
+ append_key(char *p, const char *key) {
1213
+ for (; '\0' != *key; p++, key++) {
1214
+ if ('/' == *key) {
1215
+ *p++ = '\\';
1216
+ }
1217
+ *p = *key;
1218
+ }
1219
+ return p;
1220
+ }
1221
+
1170
1222
  /* Document-method: parse
1171
1223
  * @see Oj::Doc.open
1172
1224
  */
@@ -1192,7 +1244,7 @@ doc_where(VALUE self) {
1192
1244
  for (lp = doc->where_path; lp <= doc->where; lp++) {
1193
1245
  leaf = *lp;
1194
1246
  if (T_HASH == leaf->parent_type) {
1195
- size += strlen((*lp)->key) + 1;
1247
+ size += esc_strlen((*lp)->key) + 1;
1196
1248
  } else if (T_ARRAY == leaf->parent_type) {
1197
1249
  size += ((*lp)->index < 100) ? 3 : 11;
1198
1250
  }
@@ -1202,7 +1254,7 @@ doc_where(VALUE self) {
1202
1254
  for (lp = doc->where_path; lp <= doc->where; lp++) {
1203
1255
  leaf = *lp;
1204
1256
  if (T_HASH == leaf->parent_type) {
1205
- p = stpcpy(p, (*lp)->key);
1257
+ p = append_key(p, (*lp)->key);
1206
1258
  } else if (T_ARRAY == leaf->parent_type) {
1207
1259
  p = ulong_fill(p, (*lp)->index);
1208
1260
  }
@@ -937,7 +937,10 @@ dump(int argc, VALUE *argv, VALUE self) {
937
937
  struct _Out out;
938
938
  struct _Options copts = oj_default_options;
939
939
  VALUE rstr;
940
-
940
+
941
+ if (1 > argc) {
942
+ rb_raise(rb_eArgError, "wrong number of arguments (0 for 1).");
943
+ }
941
944
  if (2 == argc) {
942
945
  oj_parse_options(argv[1], &copts);
943
946
  }
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Oj
3
3
  # Current version of the module.
4
- VERSION = '2.18.0'
4
+ VERSION = '2.18.1'
5
5
  end
@@ -1,24 +1,19 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
3
 
4
- $VERBOSE = true
5
-
6
- here = File.expand_path(File.dirname(__FILE__))
7
- $: << File.dirname(__FILE__)
8
- $: << File.join(File.dirname(here), 'ext')
9
- $: << File.join(File.dirname(here), 'lib')
4
+ $: << File.join(File.dirname(__FILE__), "../lib")
5
+ $: << File.join(File.dirname(__FILE__), "../ext")
10
6
 
11
7
  require 'oj'
12
8
 
13
- Oj.mimic_JSON()
14
-
15
- class Foo
16
- def as_json
17
- { foo: 'bar' }
9
+ class A < BasicObject
10
+ def initialize(data)
11
+ @data = data
18
12
  end
19
13
  end
20
14
 
21
- opts = {}
15
+ a = A.new("xyz")
16
+
17
+ json = Oj.dump(a, mode: :compat, use_to_json: true)
18
+ #=> NoMethodError: undefined method `to_hash' for #<A:0x007fae03de1dc8>
22
19
 
23
- puts Foo.new.to_json
24
- puts Foo.new.to_json(opts)
@@ -174,6 +174,20 @@ class DocTest < Minitest::Test
174
174
  end
175
175
  end
176
176
 
177
+ def test_move_slash
178
+ Oj::Doc.open(%|{"top":{"a/b":3}}|) do |doc|
179
+ doc.move('top/a\/b')
180
+ assert_equal('/top/a\/b', doc.where?)
181
+ end
182
+ end
183
+
184
+ def test_fetch_slash
185
+ Oj::Doc.open(%|{"a/b":3}|) do |doc|
186
+ x = doc.fetch('a\/b')
187
+ assert_equal(3, x)
188
+ end
189
+ end
190
+
177
191
  def test_move_relative
178
192
  Oj::Doc.open($json1) do |doc|
179
193
  [['/', 'array', '/array'],
metadata CHANGED
@@ -1,55 +1,65 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: oj
3
- version: !ruby/object:Gem::Version
4
- version: 2.18.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.18.1
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2016-11-26 00:00:00 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
11
+ date: 2017-01-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
15
14
  name: rake-compiler
16
- prerelease: false
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: "0.9"
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
22
20
  type: :development
23
- version_requirements: *id001
24
- - !ruby/object:Gem::Dependency
25
- name: minitest
26
21
  prerelease: false
27
- requirement: &id002 !ruby/object:Gem::Requirement
28
- requirements:
29
- - - ~>
30
- - !ruby/object:Gem::Version
31
- version: "5"
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5'
32
34
  type: :development
33
- version_requirements: *id002
34
- - !ruby/object:Gem::Dependency
35
- name: rails
36
35
  prerelease: false
37
- requirement: &id003 !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ~>
40
- - !ruby/object:Gem::Version
41
- version: "4"
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4'
42
48
  type: :development
43
- version_requirements: *id003
44
- description: "The fastest JSON parser and object serializer. "
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4'
55
+ description: 'The fastest JSON parser and object serializer. '
45
56
  email: peter@ohler.com
46
57
  executables: []
47
-
48
- extensions:
58
+ extensions:
49
59
  - ext/oj/extconf.rb
50
- extra_rdoc_files:
60
+ extra_rdoc_files:
51
61
  - README.md
52
- files:
62
+ files:
53
63
  - LICENSE
54
64
  - README.md
55
65
  - ext/oj/buf.h
@@ -160,96 +170,95 @@ files:
160
170
  - test/test_writer.rb
161
171
  - test/write_timebars.rb
162
172
  homepage: http://www.ohler.com/oj
163
- licenses:
173
+ licenses:
164
174
  - MIT
165
175
  metadata: {}
166
-
167
176
  post_install_message:
168
- rdoc_options:
169
- - --main
177
+ rdoc_options:
178
+ - "--main"
170
179
  - README.md
171
- require_paths:
180
+ require_paths:
172
181
  - lib
173
- required_ruby_version: !ruby/object:Gem::Requirement
174
- requirements:
175
- - &id004
176
- - ">="
177
- - !ruby/object:Gem::Version
178
- version: "0"
179
- required_rubygems_version: !ruby/object:Gem::Requirement
180
- requirements:
181
- - *id004
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
182
192
  requirements: []
183
-
184
193
  rubyforge_project: oj
185
- rubygems_version: 2.2.2
194
+ rubygems_version: 2.5.2
186
195
  signing_key:
187
196
  specification_version: 4
188
197
  summary: A fast JSON parser and serializer.
189
- test_files:
190
- - test/_test_active.rb
191
- - test/_test_active_mimic.rb
192
- - test/_test_mimic_rails.rb
193
- - test/activesupport_datetime_test.rb
194
- - test/bug.rb
195
- - test/bug2.rb
198
+ test_files:
199
+ - test/perf_object.rb
200
+ - test/test_hash.rb
196
201
  - test/bug3.rb
197
- - test/bug_fast.rb
198
- - test/bug_load.rb
202
+ - test/write_timebars.rb
203
+ - test/test_writer.rb
204
+ - test/russian.rb
205
+ - test/test_gc.rb
206
+ - test/_test_active_mimic.rb
207
+ - test/test_serializer.rb
208
+ - test/sample/file.rb
209
+ - test/sample/group.rb
210
+ - test/sample/oval.rb
211
+ - test/sample/rect.rb
212
+ - test/sample/hasprops.rb
213
+ - test/sample/layer.rb
214
+ - test/sample/text.rb
215
+ - test/sample/doc.rb
216
+ - test/sample/line.rb
217
+ - test/sample/dir.rb
218
+ - test/sample/shape.rb
219
+ - test/sample/change.rb
199
220
  - test/crash.rb
200
- - test/example.rb
201
- - test/files.rb
202
- - test/foo.rb
203
- - test/helper.rb
204
221
  - test/io.rb
222
+ - test/test_object.rb
223
+ - test/struct.rb
205
224
  - test/mod.rb
206
- - test/perf.rb
207
- - test/perf_compat.rb
208
- - test/perf_fast.rb
209
- - test/perf_file.rb
210
- - test/perf_object.rb
211
- - test/perf_saj.rb
212
- - test/perf_scp.rb
213
- - test/perf_simple.rb
214
- - test/perf_strict.rb
215
- - test/rails.rb
216
- - test/russian.rb
217
225
  - test/sample.rb
218
- - test/sample_json.rb
219
- - test/struct.rb
220
- - test/test_compat.rb
221
- - test/test_debian.rb
222
- - test/test_fast.rb
223
- - test/test_file.rb
224
- - test/test_gc.rb
225
- - test/test_hash.rb
226
- - test/test_object.rb
226
+ - test/perf_scp.rb
227
+ - test/bug2.rb
227
228
  - test/test_saj.rb
228
- - test/test_scp.rb
229
- - test/test_serializer.rb
230
229
  - test/test_strict.rb
230
+ - test/perf_saj.rb
231
+ - test/perf_simple.rb
232
+ - test/perf_fast.rb
233
+ - test/example.rb
234
+ - test/_test_active.rb
235
+ - test/perf_compat.rb
231
236
  - test/test_various.rb
232
- - test/test_writer.rb
233
- - test/write_timebars.rb
237
+ - test/activesupport_datetime_test.rb
238
+ - test/test_scp.rb
239
+ - test/bug_load.rb
240
+ - test/files.rb
241
+ - test/foo.rb
242
+ - test/isolated/test_mimic_rails_after.rb
243
+ - test/isolated/test_mimic_rails_datetime.rb
244
+ - test/isolated/test_mimic_redefine.rb
245
+ - test/isolated/test_mimic_as_json.rb
234
246
  - test/isolated/shared.rb
235
- - test/isolated/test_mimic_after.rb
236
247
  - test/isolated/test_mimic_alone.rb
237
- - test/isolated/test_mimic_as_json.rb
248
+ - test/isolated/test_mimic_after.rb
238
249
  - test/isolated/test_mimic_before.rb
239
- - test/isolated/test_mimic_define.rb
240
- - test/isolated/test_mimic_rails_after.rb
241
250
  - test/isolated/test_mimic_rails_before.rb
242
- - test/isolated/test_mimic_rails_datetime.rb
243
- - test/isolated/test_mimic_redefine.rb
244
- - test/sample/change.rb
245
- - test/sample/dir.rb
246
- - test/sample/doc.rb
247
- - test/sample/file.rb
248
- - test/sample/group.rb
249
- - test/sample/hasprops.rb
250
- - test/sample/layer.rb
251
- - test/sample/line.rb
252
- - test/sample/oval.rb
253
- - test/sample/rect.rb
254
- - test/sample/shape.rb
255
- - test/sample/text.rb
251
+ - test/isolated/test_mimic_define.rb
252
+ - test/_test_mimic_rails.rb
253
+ - test/test_file.rb
254
+ - test/bug.rb
255
+ - test/sample_json.rb
256
+ - test/test_debian.rb
257
+ - test/test_fast.rb
258
+ - test/rails.rb
259
+ - test/perf_file.rb
260
+ - test/test_compat.rb
261
+ - test/helper.rb
262
+ - test/perf.rb
263
+ - test/bug_fast.rb
264
+ - test/perf_strict.rb