netstring 0.0.2 → 0.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58bf8216c488dc9bf16c5f2826816f32e9d326c0
4
- data.tar.gz: fe341a3b67a1fab40772771588180ecb193712a8
3
+ metadata.gz: 8c7413e78748dc8d4164d0b52e3fd9ee9a7a16f3
4
+ data.tar.gz: ec15f3dfdb3bc4356eff236b43baa108eb715b66
5
5
  SHA512:
6
- metadata.gz: 4891518572806c60b05d3f4c8726c2039b0ce40a108fa68694771250075dc8f1c6a5613fa0312ab2c7c2eabdc2b40d3169c567143fd7a5930de78004feb25942
7
- data.tar.gz: 5c2cf2d5e27208946073ec204c3b01adf3cc797763ed5567b4020c1dd6ba2d5a644736a4ba8cad282b645428bc97a8c9dc5e9c0bda1a22c3e457b4c326e3e2bc
6
+ metadata.gz: baa24f24d5718efed70f3f292419d037bfd9ff8b9daff4021c1829d4725e039727ce79a7d7496d7ca44e8ad7d13bca4961036d1151a053d7892aac9f1e9bad54
7
+ data.tar.gz: 432982bb228965a513e982bce142cd0a6e04c2c2ab50137eb07e20b293588ee95331a4a7d6a94f7c636f95f6870c3f18699891c37939042182ca9ded1884a472
@@ -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.size}:#{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[match.end(0) + size] == ','
43
+ unless n.byteslice(match.end(0) + size) == ','
44
44
  raise Error, 'expected "," delimiter'
45
45
  end
46
- Netstring.new(n, match.end(0), size)
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[start, length])
57
+ super(n.byteslice(start, length))
58
58
 
59
- @netstring = n[0, start + length + 1]
59
+ @netstring = n.byteslice(0, start + length + 1)
60
60
  end
61
61
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "netstring"
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["James McKinney"]
8
8
  s.homepage = "http://github.com/jpmckinney/netstring"
@@ -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.2
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-24 00:00:00.000000000 Z
11
+ date: 2015-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coveralls