yajl-ruby 0.7.6 → 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of yajl-ruby might be problematic. Click here for more details.
- data/CHANGELOG.md +5 -0
- data/README.rdoc +6 -6
- data/Rakefile +18 -13
- data/VERSION.yml +2 -2
- data/benchmark/encode.rb +3 -5
- data/benchmark/encode_json_and_marshal.rb +2 -0
- data/benchmark/encode_json_and_yaml.rb +2 -0
- data/benchmark/http.rb +2 -0
- data/benchmark/parse.rb +3 -5
- data/benchmark/parse_json_and_marshal.rb +2 -0
- data/benchmark/parse_json_and_yaml.rb +2 -0
- data/benchmark/parse_stream.rb +3 -5
- data/ext/yajl_ext.c +33 -54
- data/ext/yajl_ext.h +1 -1
- data/lib/yajl.rb +1 -1
- data/spec/encoding/encoding_spec.rb +17 -0
- data/spec/parsing/one_off_spec.rb +17 -0
- data/spec/spec_helper.rb +10 -1
- data/yajl-ruby.gemspec +6 -5
- metadata +7 -4
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.7.7 (July 12th, 2010)
|
4
|
+
* full string encoding support for 1.9, respecting Encoding.default_internal
|
5
|
+
* refactor the #to_json function bodies into a C macro
|
6
|
+
* some misc code cleanup in the benchmark scripts
|
7
|
+
|
3
8
|
## 0.7.6 (May 1st, 2010)
|
4
9
|
* use memcmp instead of strcmp for invalid Fixnum check
|
5
10
|
* add a spec to verify unicode chars can be used as keys
|
data/README.rdoc
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
This gem is a C binding to the excellent YAJL JSON parsing and generation library.
|
4
4
|
|
5
|
-
You can read more info at the
|
5
|
+
You can read more info at the project's website http://lloyd.github.com/yajl or check out its code at http://github.com/lloyd/yajl.
|
6
6
|
|
7
7
|
== Features
|
8
8
|
|
@@ -113,7 +113,7 @@ unserialized off the stream. For the case of this Twitter Streaming API call, th
|
|
113
113
|
The code below is all that's needed to make the request and stream unserialized Ruby hashes off the response, continuously.
|
114
114
|
You'll note that I've enabled the :symbolize_keys parser option as well. Doing so is much more efficient for parsing JSON streams with
|
115
115
|
lots of repetitive keys - for things like result sets or multiple API requests - than the same parse with string keys.
|
116
|
-
This is because Ruby will reuse (and never GC)
|
116
|
+
This is because Ruby will reuse (and never GC) its symbol table. Be that as it may, if you want to parse JSON strings with random key names
|
117
117
|
it's much better to leave string keys enabled (the default), so they can get GC'd later.
|
118
118
|
|
119
119
|
require 'uri'
|
@@ -172,7 +172,7 @@ Using EventMachine and you want to encode and send in chunks?
|
|
172
172
|
end
|
173
173
|
|
174
174
|
def connection_completed
|
175
|
-
# The encoder will do
|
175
|
+
# The encoder will do its best to hand you data in chunks that
|
176
176
|
# are around 8kb (but you may see some that are larger)
|
177
177
|
#
|
178
178
|
# It should be noted that you could have also assigned the _on_progress_ callback
|
@@ -205,7 +205,7 @@ The JSON gem compatibility API isn't enabled by default. You have to explicitly
|
|
205
205
|
|
206
206
|
That's right, you can just replace "require 'json'" with the line above and you're done!
|
207
207
|
|
208
|
-
This will require yajl-ruby itself, as well as enable
|
208
|
+
This will require yajl-ruby itself, as well as enable its JSON gem compatibility API.
|
209
209
|
|
210
210
|
This includes the following API:
|
211
211
|
|
@@ -231,8 +231,8 @@ After I finished implementation - this library performs close to the same as the
|
|
231
231
|
|
232
232
|
But on larger files, and higher amounts of iteration, this library was around 2x faster than JSON.parse.
|
233
233
|
|
234
|
-
The main benefit of this library is in
|
235
|
-
Since it's able to parse the stream in chunks,
|
234
|
+
The main benefit of this library is in its memory usage.
|
235
|
+
Since it's able to parse the stream in chunks, its memory requirements are very, very low.
|
236
236
|
|
237
237
|
Here's what parsing a 2.43MB JSON file off the filesystem 20 times looks like:
|
238
238
|
|
data/Rakefile
CHANGED
@@ -8,7 +8,7 @@ begin
|
|
8
8
|
gem.homepage = "http://github.com/brianmario/yajl-ruby"
|
9
9
|
gem.authors = ["Brian Lopez", "Lloyd Hilaiel"]
|
10
10
|
gem.require_paths = ["lib", "ext"]
|
11
|
-
gem.extra_rdoc_files = `git ls-files *.rdoc`.split("\n")
|
11
|
+
gem.extra_rdoc_files = `git ls-files *.rdoc`.split("\n") << 'ext/yajl.c'
|
12
12
|
gem.files = `git ls-files`.split("\n")
|
13
13
|
gem.extensions = ["ext/extconf.rb"]
|
14
14
|
gem.files.include %w(lib/jeweler/templates/.document lib/jeweler/templates/.gitignore)
|
@@ -18,18 +18,23 @@ rescue LoadError
|
|
18
18
|
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler -s http://gems.github.com"
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
require '
|
21
|
+
begin
|
22
|
+
require 'rake'
|
23
|
+
require 'spec/rake/spectask'
|
23
24
|
|
24
|
-
desc "Run all examples with RCov"
|
25
|
-
Spec::Rake::SpecTask.new('spec:rcov') do |t|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
desc "Run all examples with RCov"
|
26
|
+
Spec::Rake::SpecTask.new('spec:rcov') do |t|
|
27
|
+
t.spec_files = FileList['spec/']
|
28
|
+
t.rcov = true
|
29
|
+
t.rcov_opts = lambda do
|
30
|
+
IO.readlines("spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
|
31
|
+
end
|
32
|
+
end
|
33
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
34
|
+
t.spec_files = FileList['spec/']
|
35
|
+
t.libs << 'ext'
|
36
|
+
t.spec_opts << '--options' << 'spec/spec.opts'
|
30
37
|
end
|
38
|
+
rescue LoadError
|
39
|
+
puts "RSpec, or one of its dependencies, is not available. Install it with: sudo gem install rspec"
|
31
40
|
end
|
32
|
-
Spec::Rake::SpecTask.new('spec') do |t|
|
33
|
-
t.spec_files = FileList['spec/']
|
34
|
-
t.spec_opts << '--options' << 'spec/spec.opts'
|
35
|
-
end
|
data/VERSION.yml
CHANGED
data/benchmark/encode.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
|
3
|
+
|
2
4
|
require 'rubygems'
|
3
5
|
require 'benchmark'
|
4
6
|
require 'yajl_ext'
|
@@ -9,12 +11,8 @@ rescue LoadError
|
|
9
11
|
end
|
10
12
|
# Can't use ActiveSuport::JSON.encode with the JSON gem loaded
|
11
13
|
# begin
|
12
|
-
# require 'active_support
|
14
|
+
# require 'active_support'
|
13
15
|
# rescue LoadError
|
14
|
-
# begin
|
15
|
-
# require 'active_support'
|
16
|
-
# rescue LoadError
|
17
|
-
# end
|
18
16
|
# end
|
19
17
|
|
20
18
|
filename = ARGV[0] || 'benchmark/subjects/ohai.json'
|
data/benchmark/http.rb
CHANGED
data/benchmark/parse.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
|
3
|
+
|
2
4
|
require 'rubygems'
|
3
5
|
require 'benchmark'
|
4
6
|
require 'yajl_ext'
|
@@ -7,12 +9,8 @@ begin
|
|
7
9
|
rescue LoadError
|
8
10
|
end
|
9
11
|
begin
|
10
|
-
require 'active_support
|
12
|
+
require 'active_support'
|
11
13
|
rescue LoadError
|
12
|
-
begin
|
13
|
-
require 'active_support'
|
14
|
-
rescue LoadError
|
15
|
-
end
|
16
14
|
end
|
17
15
|
|
18
16
|
filename = ARGV[0] || 'benchmark/subjects/twitter_search.json'
|
data/benchmark/parse_stream.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
|
3
|
+
|
2
4
|
require 'rubygems'
|
3
5
|
require 'benchmark'
|
4
6
|
require 'yajl_ext'
|
@@ -7,12 +9,8 @@ begin
|
|
7
9
|
rescue LoadError
|
8
10
|
end
|
9
11
|
begin
|
10
|
-
require 'active_support
|
12
|
+
require 'active_support'
|
11
13
|
rescue LoadError
|
12
|
-
begin
|
13
|
-
require 'active_support'
|
14
|
-
rescue LoadError
|
15
|
-
end
|
16
14
|
end
|
17
15
|
|
18
16
|
filename = 'benchmark/subjects/twitter_stream.json'
|
data/ext/yajl_ext.c
CHANGED
@@ -23,6 +23,15 @@
|
|
23
23
|
|
24
24
|
#include "yajl_ext.h"
|
25
25
|
|
26
|
+
#define YAJL_RB_TO_JSON \
|
27
|
+
VALUE rb_encoder; \
|
28
|
+
rb_scan_args(argc, argv, "01", &rb_encoder); \
|
29
|
+
VALUE cls = rb_obj_class(rb_encoder); \
|
30
|
+
if (rb_encoder == Qnil || cls != cEncoder) { \
|
31
|
+
rb_encoder = rb_yajl_encoder_new(0, NULL, cEncoder); \
|
32
|
+
} \
|
33
|
+
return rb_yajl_encoder_encode(1, &self, rb_encoder); \
|
34
|
+
|
26
35
|
/* Helpers for building objects */
|
27
36
|
inline void yajl_check_and_fire_callback(void * ctx) {
|
28
37
|
yajl_parser_wrapper * wrapper;
|
@@ -247,7 +256,11 @@ static int yajl_found_number(void * ctx, const char * numberVal, unsigned int nu
|
|
247
256
|
static int yajl_found_string(void * ctx, const unsigned char * stringVal, unsigned int stringLen) {
|
248
257
|
VALUE str = rb_str_new((const char *)stringVal, stringLen);
|
249
258
|
#ifdef HAVE_RUBY_ENCODING_H
|
250
|
-
|
259
|
+
rb_encoding *default_internal_enc = rb_default_internal_encoding();
|
260
|
+
rb_enc_associate(str, utf8Encoding);
|
261
|
+
if (default_internal_enc) {
|
262
|
+
str = rb_str_export_to_enc(str, default_internal_enc);
|
263
|
+
}
|
251
264
|
#endif
|
252
265
|
yajl_set_static_value(ctx, str);
|
253
266
|
yajl_check_and_fire_callback(ctx);
|
@@ -258,6 +271,9 @@ static int yajl_found_hash_key(void * ctx, const unsigned char * stringVal, unsi
|
|
258
271
|
yajl_parser_wrapper * wrapper;
|
259
272
|
GetParser((VALUE)ctx, wrapper);
|
260
273
|
VALUE keyStr;
|
274
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
275
|
+
rb_encoding *default_internal_enc = rb_default_internal_encoding();
|
276
|
+
#endif
|
261
277
|
|
262
278
|
if (wrapper->symbolizeKeys) {
|
263
279
|
char buf[stringLen+1];
|
@@ -267,7 +283,10 @@ static int yajl_found_hash_key(void * ctx, const unsigned char * stringVal, unsi
|
|
267
283
|
} else {
|
268
284
|
keyStr = rb_str_new((const char *)stringVal, stringLen);
|
269
285
|
#ifdef HAVE_RUBY_ENCODING_H
|
270
|
-
|
286
|
+
rb_enc_associate(keyStr, utf8Encoding);
|
287
|
+
if (default_internal_enc) {
|
288
|
+
keyStr = rb_str_export_to_enc(keyStr, default_internal_enc);
|
289
|
+
}
|
271
290
|
#endif
|
272
291
|
yajl_set_static_value(ctx, keyStr);
|
273
292
|
}
|
@@ -538,7 +557,7 @@ static VALUE rb_yajl_encoder_new(int argc, VALUE * argv, VALUE klass) {
|
|
538
557
|
indent = rb_hash_aref(opts, sym_indent);
|
539
558
|
if (indent != Qnil) {
|
540
559
|
#ifdef HAVE_RUBY_ENCODING_H
|
541
|
-
|
560
|
+
indent = rb_str_export_to_enc(indent, utf8Encoding);
|
542
561
|
#endif
|
543
562
|
Check_Type(indent, T_STRING);
|
544
563
|
indentString = RSTRING_PTR(indent);
|
@@ -554,7 +573,7 @@ static VALUE rb_yajl_encoder_new(int argc, VALUE * argv, VALUE klass) {
|
|
554
573
|
wrapper->terminator = rb_hash_aref(opts, sym_terminator);
|
555
574
|
#ifdef HAVE_RUBY_ENCODING_H
|
556
575
|
if (TYPE(wrapper->terminator) == T_STRING) {
|
557
|
-
|
576
|
+
wrapper->terminator = rb_str_export_to_enc(wrapper->terminator, utf8Encoding);
|
558
577
|
}
|
559
578
|
#endif
|
560
579
|
} else {
|
@@ -620,7 +639,7 @@ static VALUE rb_yajl_encoder_encode(int argc, VALUE * argv, VALUE self) {
|
|
620
639
|
yajl_gen_get_buf(wrapper->encoder, &buffer, &len);
|
621
640
|
outBuff = rb_str_new((const char *)buffer, len);
|
622
641
|
#ifdef HAVE_RUBY_ENCODING_H
|
623
|
-
|
642
|
+
rb_enc_associate(outBuff, utf8Encoding);
|
624
643
|
#endif
|
625
644
|
yajl_gen_clear(wrapper->encoder);
|
626
645
|
|
@@ -678,12 +697,7 @@ static VALUE rb_yajl_encoder_set_progress_cb(VALUE self, VALUE callback) {
|
|
678
697
|
* Encodes an instance of Hash to JSON
|
679
698
|
*/
|
680
699
|
static VALUE rb_yajl_json_ext_hash_to_json(int argc, VALUE * argv, VALUE self) {
|
681
|
-
|
682
|
-
rb_scan_args(argc, argv, "01", &rb_encoder);
|
683
|
-
if (rb_encoder == Qnil) {
|
684
|
-
rb_encoder = rb_yajl_encoder_new(0, NULL, cEncoder);
|
685
|
-
}
|
686
|
-
return rb_yajl_encoder_encode(1, &self, rb_encoder);
|
700
|
+
YAJL_RB_TO_JSON;
|
687
701
|
}
|
688
702
|
|
689
703
|
/*
|
@@ -699,12 +713,7 @@ static VALUE rb_yajl_json_ext_hash_to_json(int argc, VALUE * argv, VALUE self) {
|
|
699
713
|
* Encodes an instance of Array to JSON
|
700
714
|
*/
|
701
715
|
static VALUE rb_yajl_json_ext_array_to_json(int argc, VALUE * argv, VALUE self) {
|
702
|
-
|
703
|
-
rb_scan_args(argc, argv, "01", &rb_encoder);
|
704
|
-
if (rb_encoder == Qnil) {
|
705
|
-
rb_encoder = rb_yajl_encoder_new(0, NULL, cEncoder);
|
706
|
-
}
|
707
|
-
return rb_yajl_encoder_encode(1, &self, rb_encoder);
|
716
|
+
YAJL_RB_TO_JSON;
|
708
717
|
}
|
709
718
|
|
710
719
|
/*
|
@@ -720,12 +729,7 @@ static VALUE rb_yajl_json_ext_array_to_json(int argc, VALUE * argv, VALUE self)
|
|
720
729
|
* Encodes an instance of Fixnum to JSON
|
721
730
|
*/
|
722
731
|
static VALUE rb_yajl_json_ext_fixnum_to_json(int argc, VALUE * argv, VALUE self) {
|
723
|
-
|
724
|
-
rb_scan_args(argc, argv, "01", &rb_encoder);
|
725
|
-
if (rb_encoder == Qnil) {
|
726
|
-
rb_encoder = rb_yajl_encoder_new(0, NULL, cEncoder);
|
727
|
-
}
|
728
|
-
return rb_yajl_encoder_encode(1, &self, rb_encoder);
|
732
|
+
YAJL_RB_TO_JSON;
|
729
733
|
}
|
730
734
|
|
731
735
|
/*
|
@@ -741,12 +745,7 @@ static VALUE rb_yajl_json_ext_fixnum_to_json(int argc, VALUE * argv, VALUE self)
|
|
741
745
|
* Encodes an instance of Float to JSON
|
742
746
|
*/
|
743
747
|
static VALUE rb_yajl_json_ext_float_to_json(int argc, VALUE * argv, VALUE self) {
|
744
|
-
|
745
|
-
rb_scan_args(argc, argv, "01", &rb_encoder);
|
746
|
-
if (rb_encoder == Qnil) {
|
747
|
-
rb_encoder = rb_yajl_encoder_new(0, NULL, cEncoder);
|
748
|
-
}
|
749
|
-
return rb_yajl_encoder_encode(1, &self, rb_encoder);
|
748
|
+
YAJL_RB_TO_JSON;
|
750
749
|
}
|
751
750
|
|
752
751
|
/*
|
@@ -762,12 +761,7 @@ static VALUE rb_yajl_json_ext_float_to_json(int argc, VALUE * argv, VALUE self)
|
|
762
761
|
* Encodes an instance of TrueClass to JSON
|
763
762
|
*/
|
764
763
|
static VALUE rb_yajl_json_ext_string_to_json(int argc, VALUE * argv, VALUE self) {
|
765
|
-
|
766
|
-
rb_scan_args(argc, argv, "01", &rb_encoder);
|
767
|
-
if (rb_encoder == Qnil) {
|
768
|
-
rb_encoder = rb_yajl_encoder_new(0, NULL, cEncoder);
|
769
|
-
}
|
770
|
-
return rb_yajl_encoder_encode(1, &self, rb_encoder);
|
764
|
+
YAJL_RB_TO_JSON;
|
771
765
|
}
|
772
766
|
|
773
767
|
/*
|
@@ -783,12 +777,7 @@ static VALUE rb_yajl_json_ext_string_to_json(int argc, VALUE * argv, VALUE self)
|
|
783
777
|
* Encodes an instance of TrueClass to JSON
|
784
778
|
*/
|
785
779
|
static VALUE rb_yajl_json_ext_true_to_json(int argc, VALUE * argv, VALUE self) {
|
786
|
-
|
787
|
-
rb_scan_args(argc, argv, "01", &rb_encoder);
|
788
|
-
if (rb_encoder == Qnil) {
|
789
|
-
rb_encoder = rb_yajl_encoder_new(0, NULL, cEncoder);
|
790
|
-
}
|
791
|
-
return rb_yajl_encoder_encode(1, &self, rb_encoder);
|
780
|
+
YAJL_RB_TO_JSON;
|
792
781
|
}
|
793
782
|
|
794
783
|
/*
|
@@ -804,12 +793,7 @@ static VALUE rb_yajl_json_ext_true_to_json(int argc, VALUE * argv, VALUE self) {
|
|
804
793
|
* Encodes an instance of FalseClass to JSON
|
805
794
|
*/
|
806
795
|
static VALUE rb_yajl_json_ext_false_to_json(int argc, VALUE * argv, VALUE self) {
|
807
|
-
|
808
|
-
rb_scan_args(argc, argv, "01", &rb_encoder);
|
809
|
-
if (rb_encoder == Qnil) {
|
810
|
-
rb_encoder = rb_yajl_encoder_new(0, NULL, cEncoder);
|
811
|
-
}
|
812
|
-
return rb_yajl_encoder_encode(1, &self, rb_encoder);
|
796
|
+
YAJL_RB_TO_JSON;
|
813
797
|
}
|
814
798
|
|
815
799
|
/*
|
@@ -825,12 +809,7 @@ static VALUE rb_yajl_json_ext_false_to_json(int argc, VALUE * argv, VALUE self)
|
|
825
809
|
* Encodes an instance of NilClass to JSON
|
826
810
|
*/
|
827
811
|
static VALUE rb_yajl_json_ext_nil_to_json(int argc, VALUE * argv, VALUE self) {
|
828
|
-
|
829
|
-
rb_scan_args(argc, argv, "01", &rb_encoder);
|
830
|
-
if (rb_encoder == Qnil) {
|
831
|
-
rb_encoder = rb_yajl_encoder_new(0, NULL, cEncoder);
|
832
|
-
}
|
833
|
-
return rb_yajl_encoder_encode(1, &self, rb_encoder);
|
812
|
+
YAJL_RB_TO_JSON;
|
834
813
|
}
|
835
814
|
|
836
815
|
/*
|
@@ -896,6 +875,6 @@ void Init_yajl_ext() {
|
|
896
875
|
sym_symbolize_keys = ID2SYM(rb_intern("symbolize_keys"));
|
897
876
|
|
898
877
|
#ifdef HAVE_RUBY_ENCODING_H
|
899
|
-
utf8Encoding =
|
878
|
+
utf8Encoding = rb_utf8_encoding();
|
900
879
|
#endif
|
901
880
|
}
|
data/ext/yajl_ext.h
CHANGED
data/lib/yajl.rb
CHANGED
@@ -13,7 +13,7 @@ require 'yajl_ext'
|
|
13
13
|
#
|
14
14
|
# Ruby bindings to the excellent Yajl (Yet Another JSON Parser) ANSI C library.
|
15
15
|
module Yajl
|
16
|
-
VERSION = "0.7.
|
16
|
+
VERSION = "0.7.7"
|
17
17
|
|
18
18
|
# For compatibility, has the same signature of Yajl::Parser.parse
|
19
19
|
def self.load(str_or_io, options={}, read_bufsize=nil, &block)
|
@@ -214,4 +214,21 @@ describe "Yajl JSON encoder" do
|
|
214
214
|
hash = {"浅草" => "<- those are unicode"}
|
215
215
|
Yajl::Encoder.encode(hash).should eql("{\"浅草\":\"<- those are unicode\"}")
|
216
216
|
end
|
217
|
+
|
218
|
+
if RUBY_VERSION =~ /^1.9/
|
219
|
+
it "should return a string encoded in utf-8 if Encoding.default_internal is nil" do
|
220
|
+
Encoding.default_internal = nil
|
221
|
+
hash = {"浅草" => "<- those are unicode"}
|
222
|
+
Yajl::Encoder.encode(hash).encoding.should eql(Encoding.find('utf-8'))
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should return a string encoded in utf-8 even if Encoding.default_internal *is* set" do
|
226
|
+
Encoding.default_internal = Encoding.find('utf-8')
|
227
|
+
hash = {"浅草" => "<- those are unicode"}
|
228
|
+
Yajl::Encoder.encode(hash).encoding.should eql(Encoding.default_internal)
|
229
|
+
Encoding.default_internal = Encoding.find('us-ascii')
|
230
|
+
hash = {"浅草" => "<- those are unicode"}
|
231
|
+
Yajl::Encoder.encode(hash).encoding.should eql(Encoding.find('utf-8'))
|
232
|
+
end
|
233
|
+
end
|
217
234
|
end
|
@@ -61,4 +61,21 @@ describe "One-off JSON examples" do
|
|
61
61
|
Yajl::Parser.parse("{\"id\": 5687389800}").should eql({"id" => 5687389800})
|
62
62
|
Yajl::Parser.parse("{\"id\": 1046289770033519442869495707521600000000}").should eql({"id" => 1046289770033519442869495707521600000000})
|
63
63
|
end
|
64
|
+
|
65
|
+
if RUBY_VERSION =~ /^1.9/
|
66
|
+
it "should return strings and hash keys in utf-8 if Encoding.default_internal is nil" do
|
67
|
+
Encoding.default_internal = nil
|
68
|
+
Yajl::Parser.parse('{"key": "value"}').keys.first.encoding.should eql(Encoding.find('utf-8'))
|
69
|
+
Yajl::Parser.parse('{"key": "value"}').values.first.encoding.should eql(Encoding.find('utf-8'))
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should return strings and hash keys encoded as specified in Encoding.default_internal if it's set" do
|
73
|
+
Encoding.default_internal = Encoding.find('utf-8')
|
74
|
+
Yajl::Parser.parse('{"key": "value"}').keys.first.encoding.should eql(Encoding.default_internal)
|
75
|
+
Yajl::Parser.parse('{"key": "value"}').values.first.encoding.should eql(Encoding.default_internal)
|
76
|
+
Encoding.default_internal = Encoding.find('us-ascii')
|
77
|
+
Yajl::Parser.parse('{"key": "value"}').keys.first.encoding.should eql(Encoding.default_internal)
|
78
|
+
Yajl::Parser.parse('{"key": "value"}').values.first.encoding.should eql(Encoding.default_internal)
|
79
|
+
end
|
80
|
+
end
|
64
81
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,16 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
|
2
3
|
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
3
4
|
|
4
5
|
require 'rubygems'
|
5
6
|
require 'yajl'
|
6
|
-
require 'active_support/core_ext/kernel/reporting'
|
7
7
|
require 'date'
|
8
|
+
|
9
|
+
module Kernel
|
10
|
+
def silence_warnings
|
11
|
+
old_verbose, $VERBOSE = $VERBOSE, nil
|
12
|
+
yield
|
13
|
+
ensure
|
14
|
+
$VERBOSE = old_verbose
|
15
|
+
end
|
16
|
+
end
|
data/yajl-ruby.gemspec
CHANGED
@@ -5,15 +5,16 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{yajl-ruby}
|
8
|
-
s.version = "0.7.
|
8
|
+
s.version = "0.7.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brian Lopez", "Lloyd Hilaiel"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-07-12}
|
13
13
|
s.email = %q{seniorlopez@gmail.com}
|
14
14
|
s.extensions = ["ext/extconf.rb"]
|
15
15
|
s.extra_rdoc_files = [
|
16
|
-
"README.rdoc"
|
16
|
+
"README.rdoc",
|
17
|
+
"ext/yajl.c"
|
17
18
|
]
|
18
19
|
s.files = [
|
19
20
|
".gitignore",
|
@@ -163,7 +164,7 @@ Gem::Specification.new do |s|
|
|
163
164
|
s.rdoc_options = ["--charset=UTF-8"]
|
164
165
|
s.require_paths = ["lib", "ext"]
|
165
166
|
s.rubyforge_project = %q{yajl-ruby}
|
166
|
-
s.rubygems_version = %q{1.3.
|
167
|
+
s.rubygems_version = %q{1.3.7}
|
167
168
|
s.summary = %q{Ruby C bindings to the excellent Yajl JSON stream-based parser library.}
|
168
169
|
s.test_files = [
|
169
170
|
"spec/encoding/encoding_spec.rb",
|
@@ -193,7 +194,7 @@ Gem::Specification.new do |s|
|
|
193
194
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
194
195
|
s.specification_version = 3
|
195
196
|
|
196
|
-
if Gem::Version.new(Gem::
|
197
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
197
198
|
else
|
198
199
|
end
|
199
200
|
else
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 7
|
8
|
-
-
|
9
|
-
version: 0.7.
|
8
|
+
- 7
|
9
|
+
version: 0.7.7
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Brian Lopez
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-07-12 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -27,6 +27,7 @@ extensions:
|
|
27
27
|
- ext/extconf.rb
|
28
28
|
extra_rdoc_files:
|
29
29
|
- README.rdoc
|
30
|
+
- ext/yajl.c
|
30
31
|
files:
|
31
32
|
- .gitignore
|
32
33
|
- CHANGELOG.md
|
@@ -181,6 +182,7 @@ require_paths:
|
|
181
182
|
- lib
|
182
183
|
- ext
|
183
184
|
required_ruby_version: !ruby/object:Gem::Requirement
|
185
|
+
none: false
|
184
186
|
requirements:
|
185
187
|
- - ">="
|
186
188
|
- !ruby/object:Gem::Version
|
@@ -188,6 +190,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
188
190
|
- 0
|
189
191
|
version: "0"
|
190
192
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
|
+
none: false
|
191
194
|
requirements:
|
192
195
|
- - ">="
|
193
196
|
- !ruby/object:Gem::Version
|
@@ -197,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
197
200
|
requirements: []
|
198
201
|
|
199
202
|
rubyforge_project: yajl-ruby
|
200
|
-
rubygems_version: 1.3.
|
203
|
+
rubygems_version: 1.3.7
|
201
204
|
signing_key:
|
202
205
|
specification_version: 3
|
203
206
|
summary: Ruby C bindings to the excellent Yajl JSON stream-based parser library.
|