bencode_ext 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.4
data/bencode_ext.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bencode_ext}
8
- s.version = "0.2.3"
8
+ s.version = "0.2.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["naquad"]
12
- s.date = %q{2011-01-15}
12
+ s.date = %q{2011-01-16}
13
13
  s.description = %q{BEncodeExt is implementation of Bencode reader/writer (BitTorent encoding) in C.}
14
14
  s.email = %q{naquad@gmail.com}
15
15
  s.extensions = ["ext/bencode_ext/extconf.rb"]
@@ -120,6 +120,9 @@ static VALUE decode(VALUE self, VALUE encoded){
120
120
  break;
121
121
  }
122
122
  case 'e':
123
+ if(NIL_P(current_container))
124
+ rb_raise(DecodeError, "Unexpected container end at %d!", rlen - len);
125
+ current_container = rb_ary_pop(container_stack);
123
126
  state = ELEMENT_END;
124
127
  NEXT_CHAR;
125
128
  break;
@@ -127,15 +130,11 @@ static VALUE decode(VALUE self, VALUE encoded){
127
130
  rb_raise(DecodeError, "Unknown element type at %d: %c!", rlen - len, *str);
128
131
  }
129
132
 
130
- if(state == ELEMENT_END){
131
- if(NIL_P(current_container))
132
- rb_raise(DecodeError, "Unexpected container end at %d!", rlen - len);
133
- current_container = rb_ary_pop(container_stack);
134
- }else if(NIL_P(current_container)){
133
+ if(NIL_P(current_container)){
135
134
  if(NIL_P(ret))
136
135
  ret = crt;
137
136
  break;
138
- }else{
137
+ }else if(state != ELEMENT_END){
139
138
  if(BUILTIN_TYPE(current_container) == T_ARRAY){
140
139
  rb_ary_push(current_container, crt);
141
140
  }else if(NIL_P(key)){
@@ -224,9 +223,9 @@ static VALUE encode(VALUE self){
224
223
  return encode(rb_id2str(SYM2ID(self)));
225
224
  }if(rb_obj_is_kind_of(self, rb_cString)){
226
225
  long len = RSTRING_LEN(self);
227
- return rb_sprintf("%d:%.*s", len, len, RSTRING_PTR(self));
226
+ return rb_sprintf("%ld:%.*s", len, len, RSTRING_PTR(self));
228
227
  }else if(rb_obj_is_kind_of(self, rb_cInteger)){
229
- return rb_sprintf("i%de", NUM2LONG(self));
228
+ return rb_sprintf("i%lde", NUM2LONG(self));
230
229
  }else if(rb_obj_is_kind_of(self, rb_cHash)){
231
230
  VALUE ret = rb_str_new2("d");
232
231
  rb_hash_foreach(self, hash_traverse, ret);
@@ -247,7 +246,7 @@ static VALUE encode(VALUE self){
247
246
 
248
247
  static int hash_traverse(VALUE key, VALUE val, VALUE str){
249
248
  if(!rb_obj_is_kind_of(key, rb_cString) && TYPE(key) != T_SYMBOL)
250
- rb_raise(EncodeError, "Keys must be strings, not %s!", rb_class2name(CLASS_OF(key)));
249
+ rb_raise(EncodeError, "Keys must be strings or symbols, not %s!", rb_class2name(CLASS_OF(key)));
251
250
 
252
251
  rb_str_concat(str, encode(key));
253
252
  rb_str_concat(str, encode(val));
@@ -321,8 +320,8 @@ static VALUE set_max_depth(VALUE self, VALUE depth){
321
320
  }
322
321
 
323
322
  void Init_bencode_ext(){
324
- readId = rb_intern("read");
325
323
  max_depth = 5000;
324
+ readId = rb_intern("read");
326
325
  BEncode = rb_define_module("BEncode");
327
326
 
328
327
  /*
@@ -23,6 +23,7 @@ class TestBencodeExt < Test::Unit::TestCase
23
23
  assert_equal([{'k' => 1}, {'k' => 2}, {'k' => {'v' => '123'}}], 'ld1:ki1eed1:ki2eed1:kd1:v3:123eee'.bdecode)
24
24
  assert_equal([[[1],1],1], 'llli1eei1eei1ee'.bdecode)
25
25
 
26
+ assert_raises(BEncode::DecodeError) { 'i1ei2e'.bdecode }
26
27
  assert_raises(BEncode::DecodeError) {'33:unpexpected_end'.bdecode }
27
28
  assert_raises(BEncode::DecodeError) { 'i1x'.bdecode }
28
29
  assert_raises(ArgumentError) { BEncode.max_depth = 1.1 }
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 3
9
- version: 0.2.3
8
+ - 4
9
+ version: 0.2.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - naquad
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-15 00:00:00 +02:00
17
+ date: 2011-01-16 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency