Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed encoding error in ruby19

  • Loading branch information...
commit 1006090c89c6d1d15419310128cc73ebfd206acc 1 parent d7ec44e
@nougad nougad authored
View
5 lib/ruby-osc.rb
@@ -1,3 +1,4 @@
+# encoding: UTF-8
require 'rubygems'
require 'eventmachine'
require 'socket' # Strange side effects with eventmachine udp client and SuperCollider
@@ -49,8 +50,8 @@ def self.encoding_directive obj #:nodoc:
case obj
when Float then [obj, 'f', 'g']
when Fixnum then [obj, 'i', 'N']
- when Blob then [[obj.size, obj], 'b', "Na*x#{ padding_size obj.size + 4 }"]
- when String then [obj, 's', "Z*x#{ padding_size obj.size + 1 }"]
+ when Blob then [[obj.bytesize, obj], 'b', "Na*x#{ padding_size obj.bytesize + 4 }"]
+ when String then [obj, 's', "Z*x#{ padding_size obj.bytesize + 1 }"]
when Time
t1, fr = (obj.to_f + 2208988800).divmod(1)
t2 = (fr * (2**32)).to_i
View
1  lib/ruby-osc/bundle.rb
@@ -1,3 +1,4 @@
+# encoding: UTF-8
module OSC
class Bundle < Array
attr_accessor :timetag
View
1  lib/ruby-osc/client.rb
@@ -1,3 +1,4 @@
+# encoding: UTF-8
# From the Funaba osc gem:
module OSC
class Client
View
3  lib/ruby-osc/message.rb
@@ -1,3 +1,4 @@
+# encoding: UTF-8
module OSC
class Message
attr_accessor :address, :time, :args
@@ -48,7 +49,7 @@ def self.decode string
when 's'
str = scanner.scan(/[^\000]+\000/)
scanner.pos += OSC.padding_size(str.size)
- args.push str.chomp("\000")
+ args.push str.chomp("\000").force_encoding("UTF-8")
when 'b'
size = scanner.scan(/.{4}/).unpack('N').first
str = scanner.scan(/.{#{ size }}/nm)
View
1  lib/ruby-osc/server.rb
@@ -1,3 +1,4 @@
+# encoding: UTF-8
module OSC
class Server
View
1  lib/ruby-osc/version.rb
@@ -1,3 +1,4 @@
+# encoding: UTF-8
module Osc
VERSION = "0.3.4"
end
View
7 spec/bundle_spec.rb
@@ -1,3 +1,4 @@
+# encoding: UTF-8
require "#{ File.dirname __FILE__ }/spec_helper"
describe Bundle do
@@ -42,7 +43,7 @@
describe 'Empty bundle nil timetag' do
before do
@bundle = Bundle.new
- @expected = "#bundle\000\000\000\000\000\000\000\000\001"
+ @expected = "#bundle\000\000\000\000\000\000\000\000\001".force_encoding("binary")
end
it_should_behave_like 'Encodable Bundle'
end
@@ -66,7 +67,7 @@
describe 'Nested bundles' do
before do
@bundle = Bundle.new( nil, Bundle.new(nil, Message.new('/a')), Message.new('/b') )
- @expected = "#bundle\000\000\000\000\000\000\000\000\001\000\000\000\034#bundle\000\000\000\000\000\000\000\000\001\000\000\000\b/a\000\000,\000\000\000\000\000\000\b/b\000\000,\000\000\000"
+ @expected = "#bundle\000\000\000\000\000\000\000\000\001\000\000\000\034#bundle\000\000\000\000\000\000\000\000\001\000\000\000\b/a\000\000,\000\000\000\000\000\000\b/b\000\000,\000\000\000".force_encoding("binary")
end
it_should_behave_like 'Encodable Bundle'
end
@@ -90,7 +91,7 @@
end
it 'Should raise OSC::DecodeError with bad encoded bundle' do
- bad_data = "#bundle\000\000\000\000\000\000\000\000\001\000\000\000\034#bundle\000\000\000\000\000\001\000\000\000\b/a\000\000,\000\000\000\000\000\000\b/b\000\000,\000\000\000"
+ bad_data = "#bundle\000\000\000\000\000\000\000\000\001\000\000\000\034#bundle\000\000\000\000\000\001\000\000\000\b/a\000\000,\000\000\000\000\000\000\b/b\000\000,\000\000\000".force_encoding("binary")
lambda { Bundle.decode bad_data }.should raise_error(DecodeError)
end
end
View
23 spec/message_spec.rb
@@ -1,3 +1,4 @@
+# encoding: UTF-8
require "#{ File.dirname __FILE__ }/spec_helper"
describe Message do
@@ -86,7 +87,7 @@
describe 'Address' do
before do
@message = Message.new('/foo/bar/long/very/long/long/long/address')
- @expected = "/foo/bar/long/very/long/long/long/address\000\000\000,\000\000\000"
+ @expected = "/foo/bar/long/very/long/long/long/address\000\000\000,\000\000\000".force_encoding("binary")
end
it_should_behave_like 'Encodable Message'
end
@@ -94,7 +95,7 @@
describe 'Integer' do
before do
@message = Message.new('/foo/barz', 2)
- @expected = "/foo/barz\000\000\000,i\000\000\000\000\000\002"
+ @expected = "/foo/barz\000\000\000,i\000\000\000\000\000\002".force_encoding("binary")
end
it_should_behave_like 'Encodable Message'
end
@@ -102,7 +103,7 @@
describe 'Negative Integer' do
before do
@message = Message.new('/foo/barz', -2)
- @expected = "/foo/barz\000\000\000,i\000\000\377\377\377\376"
+ @expected = "/foo/barz\000\000\000,i\000\000\377\377\377\376".force_encoding("binary")
end
it_should_behave_like 'Encodable Message'
end
@@ -126,7 +127,15 @@
describe 'String' do
before do
@message = Message.new('/foo/bar', 'a string to encode')
- @expected = "/foo/bar\000\000\000\000,s\000\000a string to encode\000\000"
+ @expected = "/foo/bar\000\000\000\000,s\000\000a string to encode\000\000".force_encoding("binary")
+ end
+ it_should_behave_like 'Encodable Message'
+ end
+
+ describe 'UTF8 String' do
+ before do
+ @message = Message.new('/foo/bar', 'a string to äncode')
+ @expected = "/foo/bar\000\000\000\000,s\000\000a string to äncode\000".force_encoding("binary")
end
it_should_behave_like 'Encodable Message'
end
@@ -142,13 +151,13 @@
describe 'Blob' do
before do
@message = Message.new('/foo/bar', Blob.new('test blob'))
- @expected = "/foo/bar\000\000\000\000,b\000\000\000\000\000\ttest blob\000\000\000"
+ @expected = "/foo/bar\000\000\000\000,b\000\000\000\000\000\ttest blob\000\000\000".force_encoding("binary")
end
it_should_behave_like 'Encodable Message'
it "should raise if size doesn't correspond and return empty message" do
lambda do
- Message.decode("/foo/bar\000\000\000\000,b\000\000\000\000\000\020test blob\000\000\000")
+ Message.decode("/foo/bar\000\000\000\000,b\000\000\000\000\000\020test blob\000\000\000".force_encoding("binary"))
end.should raise_error
end
end
@@ -156,7 +165,7 @@
describe 'Lots of ints' do
before do
@message = Message.new('/bar/foo', 4, 3, 2, 1)
- @expected = "/bar/foo\000\000\000\000,iiii\000\000\000\000\000\000\004\000\000\000\003\000\000\000\002\000\000\000\001"
+ @expected = "/bar/foo\000\000\000\000,iiii\000\000\000\000\000\000\004\000\000\000\003\000\000\000\002\000\000\000\001".force_encoding("binary")
end
it_should_behave_like 'Encodable Message'
end
View
1  spec/server_spec.rb
@@ -1,3 +1,4 @@
+# encoding: UTF-8
require "#{ File.dirname __FILE__ }/spec_helper"
describe Server do
View
10 spec/spec_helper.rb
@@ -1,7 +1,17 @@
+# encoding: UTF-8
require 'rubygems'
require 'rspec'
$:.unshift( File.join( File.dirname( __FILE__), '..', 'lib' ) )
+if RUBY_VERSION.to_f < 1.9
+ class String
+ def force_encoding x
+ # Nothing
+ self
+ end
+ end
+end
+
require 'ruby-osc'
include OSC
Please sign in to comment.
Something went wrong with that request. Please try again.