oj 2.18.0 → 2.18.1
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 +7 -7
- data/README.md +1 -12
- data/ext/oj/fast.c +58 -6
- data/ext/oj/oj.c +4 -1
- data/lib/oj/version.rb +1 -1
- data/test/foo.rb +9 -14
- data/test/test_fast.rb +14 -0
- metadata +116 -107
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
|
data/ext/oj/fast.c
CHANGED
@@ -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 =
|
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 (
|
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 =
|
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 (
|
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 +=
|
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 =
|
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
|
}
|
data/ext/oj/oj.c
CHANGED
@@ -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
|
}
|
data/lib/oj/version.rb
CHANGED
data/test/foo.rb
CHANGED
@@ -1,24 +1,19 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# encoding: UTF-8
|
3
3
|
|
4
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
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)
|
data/test/test_fast.rb
CHANGED
@@ -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.
|
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
|
-
|
13
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
28
|
-
requirements:
|
29
|
-
- - ~>
|
30
|
-
- !ruby/object:Gem::Version
|
31
|
-
version:
|
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
|
-
|
38
|
-
requirements:
|
39
|
-
- - ~>
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version:
|
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
|
-
|
44
|
-
|
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
|
-
-
|
176
|
-
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
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.
|
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/
|
191
|
-
- test/
|
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/
|
198
|
-
- test/
|
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/
|
219
|
-
- test/
|
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/
|
233
|
-
- test/
|
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/
|
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/
|
243
|
-
- test/
|
244
|
-
- test/
|
245
|
-
- test/
|
246
|
-
- test/
|
247
|
-
- test/
|
248
|
-
- test/
|
249
|
-
- test/
|
250
|
-
- test/
|
251
|
-
- test/
|
252
|
-
- test/
|
253
|
-
- test/
|
254
|
-
- test/
|
255
|
-
- test/
|
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
|