brianmario-yajl-ruby 0.6.1 → 0.6.3

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.
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.3 (August 25th, 2009)
4
+ * Fixed a bug in the JSON gem compatibility API where strings weren't being properly escaped
5
+
6
+ ## 0.6.2 (August 25th, 2009)
7
+ * Fixed a bug surfaced by an existing library providing a to_json method, and Yajl would double-quote the values provided
8
+
3
9
  ## 0.6.1 (August 20th, 2009)
4
10
  * Fixed a bug in Yajl::HttpStream where responses contained multiple JSON strings but weren't Transfer-Encoding: chunked (thanks @dacort!)
5
11
 
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 6
3
- :patch: 1
3
+ :patch: 3
4
4
  :major: 0
@@ -30,7 +30,7 @@ Benchmark.bm { |x|
30
30
  }
31
31
 
32
32
  # YAML Section
33
- filename = 'benchmark/subjects/contacts.yml'
33
+ filename = 'benchmark/subjects/ohai.yml'
34
34
  yml = File.new(filename, 'r')
35
35
  data = YAML.load_stream(yml)
36
36
  yml.close
@@ -35,7 +35,7 @@ Benchmark.bm { |x|
35
35
  json.close
36
36
 
37
37
  # YAML section
38
- filename = 'benchmark/subjects/contacts.yml'
38
+ filename = 'benchmark/subjects/ohai.yml'
39
39
  yaml = File.new(filename, 'r')
40
40
 
41
41
  # warm up the filesystem
@@ -96,7 +96,8 @@ extern "C" {
96
96
  unsigned int len);
97
97
  yajl_gen_status YAJL_API yajl_gen_string(yajl_gen hand,
98
98
  const unsigned char * str,
99
- unsigned int len);
99
+ unsigned int len,
100
+ int quote);
100
101
  yajl_gen_status YAJL_API yajl_gen_null(yajl_gen hand);
101
102
  yajl_gen_status YAJL_API yajl_gen_bool(yajl_gen hand, int boolean);
102
103
  yajl_gen_status YAJL_API yajl_gen_map_open(yajl_gen hand);
@@ -79,6 +79,7 @@ void yajl_encode_part(void * wrapper, VALUE obj, VALUE io) {
79
79
  int idx = 0;
80
80
  const unsigned char * buffer;
81
81
  unsigned int len;
82
+ int quote_strings = 1;
82
83
 
83
84
  if (io != Qnil || w->on_progress_callback != Qnil) {
84
85
  status = yajl_gen_get_buf(w->encoder, &buffer, &len);
@@ -135,15 +136,16 @@ void yajl_encode_part(void * wrapper, VALUE obj, VALUE io) {
135
136
  status = yajl_gen_number(w->encoder, RSTRING_PTR(str), (unsigned int)RSTRING_LEN(str));
136
137
  break;
137
138
  case T_STRING:
138
- status = yajl_gen_string(w->encoder, (const unsigned char *)RSTRING_PTR(obj), (unsigned int)RSTRING_LEN(obj));
139
+ status = yajl_gen_string(w->encoder, (const unsigned char *)RSTRING_PTR(obj), (unsigned int)RSTRING_LEN(obj), 1);
139
140
  break;
140
141
  default:
141
142
  if (rb_respond_to(obj, intern_to_json)) {
142
143
  str = rb_funcall(obj, intern_to_json, 0);
144
+ quote_strings = 0; // this lets us append on to the buffer without Yajl quoting it again
143
145
  } else {
144
146
  str = rb_funcall(obj, intern_to_s, 0);
145
147
  }
146
- status = yajl_gen_string(w->encoder, (const unsigned char *)RSTRING_PTR(str), (unsigned int)RSTRING_LEN(str));
148
+ status = yajl_gen_string(w->encoder, (const unsigned char *)RSTRING_PTR(str), (unsigned int)RSTRING_LEN(str), quote_strings);
147
149
  break;
148
150
  }
149
151
  }
@@ -190,12 +190,17 @@ yajl_gen_number(yajl_gen g, const char * s, unsigned int l)
190
190
 
191
191
  yajl_gen_status
192
192
  yajl_gen_string(yajl_gen g, const unsigned char * str,
193
- unsigned int len)
193
+ unsigned int len, int quote)
194
194
  {
195
195
  ENSURE_VALID_STATE; INSERT_SEP; INSERT_WHITESPACE;
196
- yajl_buf_append(g->buf, "\"", 1);
197
- yajl_string_encode(g->buf, str, len);
198
- yajl_buf_append(g->buf, "\"", 1);
196
+ if (quote) {
197
+ yajl_buf_append(g->buf, "\"", 1);
198
+ yajl_string_encode(g->buf, str, len);
199
+ yajl_buf_append(g->buf, "\"", 1);
200
+ } else {
201
+ yajl_buf_append(g->buf, str, len);
202
+ }
203
+
199
204
  APPENDED_ATOM;
200
205
  FINAL_NEWLINE;
201
206
  return yajl_gen_status_ok;
@@ -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.6.1"
16
+ VERSION = "0.6.3"
17
17
 
18
18
  class Parser
19
19
  # A helper method for parse-and-forget use-cases
@@ -8,7 +8,7 @@ Yajl::Encoder.enable_json_gem_compatability
8
8
  # Our fallback to_json definition
9
9
  class Object
10
10
  def to_json(*args, &block)
11
- to_s
11
+ "\"#{to_s}\""
12
12
  end
13
13
  end
14
14
 
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
3
3
 
4
4
  class Dummy2
5
5
  def to_json
6
- "hawtness"
6
+ '"hawtness"'
7
7
  end
8
8
  end
9
9
 
@@ -53,16 +53,16 @@ describe "JSON Gem compatability API" do
53
53
 
54
54
  it "should encode arbitrary classes via their default to_json method" do
55
55
  d = Dummy.new
56
- d.to_json.should == "#{d.to_s}"
56
+ d.to_json.should == "\"#{d.to_s}\""
57
57
 
58
58
  t = Time.now
59
- t.to_json.should == "#{t.to_s}"
59
+ t.to_json.should == "\"#{t.to_s}\""
60
60
 
61
61
  da = Date.today
62
- da.to_json.should == "#{da.to_s}"
62
+ da.to_json.should == "\"#{da.to_s}\""
63
63
 
64
64
  dt = DateTime.new
65
- dt.to_json.should == "#{dt.to_s}"
65
+ dt.to_json.should == "\"#{dt.to_s}\""
66
66
  end
67
67
 
68
68
  context "ported tests for Unicode" do
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{yajl-ruby}
8
- s.version = "0.6.1"
8
+ s.version = "0.6.3"
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{2009-08-20}
12
+ s.date = %q{2009-08-25}
13
13
  s.email = %q{seniorlopez@gmail.com}
14
14
  s.extensions = ["ext/extconf.rb"]
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brianmario-yajl-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Lopez
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-08-20 00:00:00 -07:00
13
+ date: 2009-08-25 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -162,7 +162,6 @@ files:
162
162
  - yajl-ruby.gemspec
163
163
  has_rdoc: false
164
164
  homepage: http://github.com/brianmario/yajl-ruby
165
- licenses:
166
165
  post_install_message:
167
166
  rdoc_options:
168
167
  - --charset=UTF-8
@@ -184,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
183
  requirements: []
185
184
 
186
185
  rubyforge_project: yajl-ruby
187
- rubygems_version: 1.3.5
186
+ rubygems_version: 1.2.0
188
187
  signing_key:
189
188
  specification_version: 3
190
189
  summary: Ruby C bindings to the excellent Yajl JSON stream-based parser library.