netstring 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/netstring.rb +5 -5
- data/netstring.gemspec +1 -1
- data/spec/netstring_spec.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c7413e78748dc8d4164d0b52e3fd9ee9a7a16f3
|
4
|
+
data.tar.gz: ec15f3dfdb3bc4356eff236b43baa108eb715b66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: baa24f24d5718efed70f3f292419d037bfd9ff8b9daff4021c1829d4725e039727ce79a7d7496d7ca44e8ad7d13bca4961036d1151a053d7892aac9f1e9bad54
|
7
|
+
data.tar.gz: 432982bb228965a513e982bce142cd0a6e04c2c2ab50137eb07e20b293588ee95331a4a7d6a94f7c636f95f6870c3f18699891c37939042182ca9ded1884a472
|
data/lib/netstring.rb
CHANGED
@@ -19,7 +19,7 @@ class Netstring < SimpleDelegator
|
|
19
19
|
unless String === s
|
20
20
|
raise Error, "#{s.inspect} is not a String"
|
21
21
|
end
|
22
|
-
"#{s.
|
22
|
+
"#{s.bytesize}:#{s},"
|
23
23
|
end
|
24
24
|
|
25
25
|
# Loads a string from a netstring.
|
@@ -40,10 +40,10 @@ class Netstring < SimpleDelegator
|
|
40
40
|
raise Error, 'bad netstring header'
|
41
41
|
end
|
42
42
|
size = Integer(match[1])
|
43
|
-
unless n
|
43
|
+
unless n.byteslice(match.end(0) + size) == ','
|
44
44
|
raise Error, 'expected "," delimiter'
|
45
45
|
end
|
46
|
-
|
46
|
+
new(n, match.end(0), size)
|
47
47
|
end
|
48
48
|
|
49
49
|
# Initializes a netstring.
|
@@ -54,8 +54,8 @@ class Netstring < SimpleDelegator
|
|
54
54
|
# @param [Integer] start the start of the string in the netstring
|
55
55
|
# @param [Integer] length the length of the string in the netstring
|
56
56
|
def initialize(n, start, length)
|
57
|
-
super(n
|
57
|
+
super(n.byteslice(start, length))
|
58
58
|
|
59
|
-
@netstring = n
|
59
|
+
@netstring = n.byteslice(0, start + length + 1)
|
60
60
|
end
|
61
61
|
end
|
data/netstring.gemspec
CHANGED
data/spec/netstring_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
RSpec.describe Netstring do
|
@@ -20,6 +21,10 @@ RSpec.describe Netstring do
|
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
24
|
+
it 'should dump a UTF-8 string' do
|
25
|
+
expect(Netstring.dump('é')).to eq('2:é,')
|
26
|
+
end
|
27
|
+
|
23
28
|
it 'should not dump a non-string' do
|
24
29
|
{
|
25
30
|
nil => 'nil',
|
@@ -42,6 +47,10 @@ RSpec.describe Netstring do
|
|
42
47
|
end
|
43
48
|
end
|
44
49
|
|
50
|
+
it 'should load a UTF-8 string' do
|
51
|
+
expect(Netstring.load('2:é,')).to eq('é')
|
52
|
+
end
|
53
|
+
|
45
54
|
it 'should not load a nonstring' do
|
46
55
|
{
|
47
56
|
nil => 'nil',
|
@@ -78,11 +87,19 @@ RSpec.describe Netstring do
|
|
78
87
|
it 'should initialize a netstring' do
|
79
88
|
expect(Netstring.new('1:x,2:xy,', 2, 1)).to eq('x')
|
80
89
|
end
|
90
|
+
|
91
|
+
it 'should initialize a UTF-8 netstring' do
|
92
|
+
expect(Netstring.new('4:éè,4:êë,', 2, 4)).to eq('éè')
|
93
|
+
end
|
81
94
|
end
|
82
95
|
|
83
96
|
describe '#netstring' do
|
84
97
|
it 'should return the netstring' do
|
85
98
|
expect(Netstring.new('1:x,2:xy,', 2, 1).netstring).to eq('1:x,')
|
86
99
|
end
|
100
|
+
|
101
|
+
it 'should return the UTF-8 netstring' do
|
102
|
+
expect(Netstring.new('4:éè,4:êë,', 2, 4).netstring).to eq('4:éè,')
|
103
|
+
end
|
87
104
|
end
|
88
105
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netstring
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James McKinney
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coveralls
|