yajl-ruby 0.7.5 → 0.7.6
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.
Potentially problematic release.
This version of yajl-ruby might be problematic. Click here for more details.
- data/CHANGELOG.md +9 -0
- data/README.rdoc +16 -11
- data/VERSION.yml +1 -1
- data/benchmark/parse.rb +1 -1
- data/examples/http/twitter_search_api.rb +1 -3
- data/examples/http/twitter_stream_api.rb +1 -1
- data/ext/extconf.rb +2 -1
- data/ext/yajl_ext.c +2 -5
- data/lib/yajl.rb +1 -1
- data/lib/yajl/http_stream.rb +5 -2
- data/spec/encoding/encoding_spec.rb +5 -11
- data/yajl-ruby.gemspec +2 -2
- metadata +3 -3
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.7.6 (May 1st, 2010)
|
4
|
+
* use memcmp instead of strcmp for invalid Fixnum check
|
5
|
+
* add a spec to verify unicode chars can be used as keys
|
6
|
+
* twitter examples updated
|
7
|
+
* only use -Wextra if ENV['DEBUG'] is set as gcc 3 doesn't know about it
|
8
|
+
* fix chunked http encoding parse logic to further comply with the spec (thanks to Sebastian Cohnen <sebastian.cohnen@gmx.net>)
|
9
|
+
* removed as_json checks and usage in encoder to prevent infinite loops
|
10
|
+
** In Rails a lot of objects return self from the as_json method - which is wrong IMO - and needs to be fixed before this feature will work properly
|
11
|
+
|
3
12
|
## 0.7.5 (March 23rd, 2010)
|
4
13
|
* check for existence of and use as_json method on custom objects
|
5
14
|
* bugfix with read buffer when parsing from an IO (thanks to Pavel Valodzka <pavel@valodzka.name>)
|
data/README.rdoc
CHANGED
@@ -62,7 +62,7 @@ only had access to chunks of it at a time. No problem!
|
|
62
62
|
(Assume we're in an EventMachine::Connection instance)
|
63
63
|
|
64
64
|
def post_init
|
65
|
-
@parser = Yajl::Parser.new
|
65
|
+
@parser = Yajl::Parser.new(:symbolize_keys => true)
|
66
66
|
end
|
67
67
|
|
68
68
|
def object_parsed(obj)
|
@@ -165,7 +165,7 @@ Using EventMachine and you want to encode and send in chunks?
|
|
165
165
|
def post_init
|
166
166
|
# Passing a :terminator character will let us determine when the encoder
|
167
167
|
# is done encoding the current object
|
168
|
-
@encoder = Yajl::Encoder.new
|
168
|
+
@encoder = Yajl::Encoder.new
|
169
169
|
motd_contents = File.read("/path/to/motd.txt")
|
170
170
|
status = File.read("/path/to/huge/status_file.txt")
|
171
171
|
@motd = {:motd => motd_contents, :system_status => status}
|
@@ -216,15 +216,14 @@ Once the compatibility API is enabled, your existing or new project should work
|
|
216
216
|
|
217
217
|
There are a lot more possibilities that I'd love to see other gems/plugins for someday.
|
218
218
|
|
219
|
-
Some ideas
|
219
|
+
Some ideas:
|
220
220
|
* parsing logs in JSON format
|
221
221
|
* a Rails plugin - DONE! (http://github.com/technoweenie/yajl-rails)
|
222
|
-
*
|
222
|
+
* official support in Rails 3 - DONE (http://github.com/rails/rails/commit/a96bf4ab5e73fccdafb78b99e8a122cc2172b505)
|
223
|
+
** and is the default (if installed) - http://github.com/rails/rails/commit/63bb955a99eb46e257655c93dd64e86ebbf05651
|
223
224
|
* Rack middleware (ideally the JSON body could be handed to the parser while it's still being received, this is apparently possible with Unicorn)
|
224
|
-
*
|
225
|
-
*
|
226
|
-
* Patch Marshal#load and Marshal#dump to use JSON? ;)
|
227
|
-
* etc...
|
225
|
+
* JSON API clients (http://github.com/brianmario/freckle-api)
|
226
|
+
* ???
|
228
227
|
|
229
228
|
== Benchmarks
|
230
229
|
|
@@ -299,7 +298,7 @@ NOTE: I converted the 2.4MB JSON file to a Hash and a dump file from Marshal.dum
|
|
299
298
|
|
300
299
|
This project includes code from the BSD licensed yajl project, copyright 2007-2009 Lloyd Hilaiel
|
301
300
|
|
302
|
-
== Special Thanks
|
301
|
+
== Special Thanks & Contributors
|
303
302
|
|
304
303
|
For those of you using yajl-ruby out in the wild, please hit me up on Twitter (brianmario) or send me a message here on the Githubs describing the site and how you're using it. I'd love to get a list going!
|
305
304
|
|
@@ -309,7 +308,13 @@ I've had a lot of inspiration, and a lot of help. Thanks to everyone who's been
|
|
309
308
|
* Josh Ferguson - http://github.com/besquared - for peer-pressuring me into getting back into C; it worked ;) Also tons of support over IM
|
310
309
|
* Jonathan Novak - http://github.com/cypriss - pointer-hacking help
|
311
310
|
* Tom Smith - http://github.com/rtomsmith - pointer-hacking help
|
312
|
-
* Rick http://github.com/technoweenie - for making an ActiveSupport patch with support for this library and teasing me that it might go into Rails 3. You sure lit a fire under my ass and I got a ton of work done because of it! :)
|
311
|
+
* Rick Olson - http://github.com/technoweenie - for making an ActiveSupport patch with support for this library and teasing me that it might go into Rails 3. You sure lit a fire under my ass and I got a ton of work done because of it! :)
|
313
312
|
* The entire Github Crew - http://github.com/ - my inspiration, time spent writing this, finding Yajl, So many-MANY other things wouldn't have been possible without this awesome service. I owe you guys some whiskey at Kilowatt.
|
314
|
-
*
|
313
|
+
* Ben Burkert - http://github.com/benburkert
|
315
314
|
* Aman Gupta - http://github.com/tmm1 - tons of suggestions and inspiration for the most recent features, and hopefully more to come ;)
|
315
|
+
* Filipe Giusti
|
316
|
+
* Jonathan George
|
317
|
+
* Luke Redpath
|
318
|
+
* Neil Berkman
|
319
|
+
* Pavel Valodzka
|
320
|
+
* Rob Sharp
|
data/VERSION.yml
CHANGED
data/benchmark/parse.rb
CHANGED
@@ -8,7 +8,5 @@ unless keywords = ARGV[0]
|
|
8
8
|
puts "\nUsage: ruby examples/http/twitter_search_api.rb keyword\n\n"
|
9
9
|
exit(0)
|
10
10
|
end
|
11
|
-
captured = 0
|
12
|
-
uri = URI.parse("http://search.twitter.com/search.json?q=#{keywords}")
|
13
11
|
|
14
|
-
puts Yajl::HttpStream.get(
|
12
|
+
puts Yajl::HttpStream.get("http://search.twitter.com/search.json?q=#{keywords}").inspect
|
@@ -11,7 +11,7 @@ unless (username = ARGV[0]) && (password = ARGV[1])
|
|
11
11
|
exit(0)
|
12
12
|
end
|
13
13
|
captured = 0
|
14
|
-
uri = URI.parse("http://#{username}:#{password}@stream.twitter.com/
|
14
|
+
uri = URI.parse("http://#{username}:#{password}@stream.twitter.com/1/statuses/sample.json")
|
15
15
|
|
16
16
|
trap('INT') {
|
17
17
|
puts "\n\nCaptured #{captured} objects from the stream"
|
data/ext/extconf.rb
CHANGED
data/ext/yajl_ext.c
CHANGED
@@ -162,7 +162,7 @@ void yajl_encode_part(void * wrapper, VALUE obj, VALUE io) {
|
|
162
162
|
str = rb_funcall(obj, intern_to_s, 0);
|
163
163
|
cptr = RSTRING_PTR(str);
|
164
164
|
len = RSTRING_LEN(str);
|
165
|
-
if (
|
165
|
+
if (memcmp(cptr, "NaN", 3) == 0 || memcmp(cptr, "Infinity", 8) == 0 || memcmp(cptr, "-Infinity", 9) == 0) {
|
166
166
|
rb_raise(cEncodeError, "'%s' is an invalid number", cptr);
|
167
167
|
}
|
168
168
|
status = yajl_gen_number(w->encoder, cptr, len);
|
@@ -173,10 +173,7 @@ void yajl_encode_part(void * wrapper, VALUE obj, VALUE io) {
|
|
173
173
|
status = yajl_gen_string(w->encoder, (const unsigned char *)cptr, len);
|
174
174
|
break;
|
175
175
|
default:
|
176
|
-
if (rb_respond_to(obj,
|
177
|
-
obj = rb_funcall(obj, intern_as_json, 0);
|
178
|
-
yajl_encode_part(w, obj, io);
|
179
|
-
} else if (rb_respond_to(obj, intern_to_json)) {
|
176
|
+
if (rb_respond_to(obj, intern_to_json)) {
|
180
177
|
str = rb_funcall(obj, intern_to_json, 0);
|
181
178
|
cptr = RSTRING_PTR(str);
|
182
179
|
len = RSTRING_LEN(str);
|
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.6"
|
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)
|
data/lib/yajl/http_stream.rb
CHANGED
@@ -147,9 +147,12 @@ module Yajl
|
|
147
147
|
if response_head[:headers]["Transfer-Encoding"] == 'chunked'
|
148
148
|
if block_given?
|
149
149
|
chunkLeft = 0
|
150
|
-
while !socket.eof? && (
|
151
|
-
|
150
|
+
while !socket.eof? && (line = socket.gets)
|
151
|
+
break if line.match /0.*?\r\n/
|
152
|
+
next if line == "\r\n"
|
153
|
+
size = line.hex
|
152
154
|
json = socket.read(size)
|
155
|
+
next if json.nil?
|
153
156
|
chunkLeft = size-json.size
|
154
157
|
if chunkLeft == 0
|
155
158
|
parser << json
|
@@ -7,12 +7,6 @@ class Dummy2
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
class Dummy3
|
11
|
-
def as_json
|
12
|
-
{:hawtness => true}
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
10
|
describe "Yajl JSON encoder" do
|
17
11
|
FILES = Dir[File.dirname(__FILE__)+'/../../benchmark/subjects/*.json']
|
18
12
|
|
@@ -161,11 +155,6 @@ describe "Yajl JSON encoder" do
|
|
161
155
|
Yajl::Encoder.encode({:foo => d}).should eql('{"foo":{"hawtness":true}}')
|
162
156
|
end
|
163
157
|
|
164
|
-
it "should check for and call #as_json if it exists on custom objects" do
|
165
|
-
d = Dummy3.new
|
166
|
-
Yajl::Encoder.encode(d).should eql('{"hawtness":true}')
|
167
|
-
end
|
168
|
-
|
169
158
|
it "should encode a hash where the key and value can be symbols" do
|
170
159
|
Yajl::Encoder.encode({:foo => :bar}).should eql('{"foo":"bar"}')
|
171
160
|
end
|
@@ -220,4 +209,9 @@ describe "Yajl JSON encoder" do
|
|
220
209
|
Yajl::Encoder.encode(-1.0/0.0)
|
221
210
|
}.should raise_error(Yajl::EncodeError)
|
222
211
|
end
|
212
|
+
|
213
|
+
it "should encode with unicode chars in the key" do
|
214
|
+
hash = {"浅草" => "<- those are unicode"}
|
215
|
+
Yajl::Encoder.encode(hash).should eql("{\"浅草\":\"<- those are unicode\"}")
|
216
|
+
end
|
223
217
|
end
|
data/yajl-ruby.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
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.6"
|
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-05-01}
|
13
13
|
s.email = %q{seniorlopez@gmail.com}
|
14
14
|
s.extensions = ["ext/extconf.rb"]
|
15
15
|
s.extra_rdoc_files = [
|
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
|
+
- 6
|
9
|
+
version: 0.7.6
|
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-05-01 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|